Commit c9c30aab authored by Adam Wujek's avatar Adam Wujek 💬 Committed by Grzegorz Daniluk

lib/lldp: get rid of tlv_offset

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 8705ee3f
...@@ -33,10 +33,10 @@ static struct wr_sockaddr addr; ...@@ -33,10 +33,10 @@ static struct wr_sockaddr addr;
static void lldp_header_tlv(int tlv_type) { static void lldp_header_tlv(int tlv_type) {
lldpdu_len = tlv_offset[tlv_type]; //lldpdu_len = tlv_offset[tlv_type];
lldpdu[lldpdu_len] = tlv_type * 2; lldpdu[lldpdu_len] = tlv_type << 1;
lldpdu[lldpdu_len + LLDP_SUBTYPE] = tlv_type_len[tlv_type]; lldpdu[lldpdu_len + LLDP_SUBTYPE] = tlv_type_len[tlv_type];
lldpdu_len += LLDP_HEADER; lldpdu_len += 2;
} }
static void lldp_add_tlv(int tlv_type) { static void lldp_add_tlv(int tlv_type) {
...@@ -66,8 +66,9 @@ static void lldp_add_tlv(int tlv_type) { ...@@ -66,8 +66,9 @@ static void lldp_add_tlv(int tlv_type) {
lldp_header_tlv(tlv_type); lldp_header_tlv(tlv_type);
/* TLV Interce Alias */ /* TLV Interce Alias */
lldpdu[lldpdu_len] = 7; lldpdu[lldpdu_len] = LLDP_ID_SUBTYPE_MAC;
strcpy(lldpdu + (lldpdu_len + LLDP_SUBTYPE), "WR Port"); get_mac_addr(mac);
memcpy(lldpdu + (lldpdu_len + LLDP_SUBTYPE), mac, 6);
break; break;
case TTL: case TTL:
/* header */ /* header */
...@@ -132,27 +133,18 @@ static void lldp_add_tlv(int tlv_type) { ...@@ -132,27 +133,18 @@ static void lldp_add_tlv(int tlv_type) {
break; break;
case USER_DEF: case USER_DEF:
/* TODO define WR TLV */ /* TODO define WR TLV */
return;
break; break;
default: default:
return;
break; break;
} }
lldpdu_len += tlv_type_len[tlv_type];
} }
static void lldp_init(void) static void lldp_update(void)
{ {
struct wr_sockaddr saddr;
int i; int i;
/* LLDP: raw ethernet*/
memset(&saddr, 0x0, sizeof(saddr));
saddr.ethertype = htons(LLDP_ETH_TYP);
lldp_socket = ptpd_netif_create_socket(&__static_lldp_socket, &saddr,
PTPD_SOCK_RAW_ETHERNET, 0);
memset(&addr, 0x0, sizeof(struct wr_sockaddr));
memcpy(addr.mac, LLDP_MCAST_MAC, 6);
/* add mandatory LLDP TLVs */ /* add mandatory LLDP TLVs */
memset(lldpdu, 0x0, LLDP_PKT_LEN); memset(lldpdu, 0x0, LLDP_PKT_LEN);
lldpdu_len = 0; lldpdu_len = 0;
...@@ -167,6 +159,23 @@ static void lldp_init(void) ...@@ -167,6 +159,23 @@ static void lldp_init(void)
lldp_add_tlv(END_LLDP); lldp_add_tlv(END_LLDP);
} }
static void lldp_init(void)
{
struct wr_sockaddr saddr;
/* LLDP: raw ethernet*/
memset(&saddr, 0x0, sizeof(saddr));
saddr.ethertype = htons(LLDP_ETH_TYP);
lldp_socket = ptpd_netif_create_socket(&__static_lldp_socket, &saddr,
PTPD_SOCK_RAW_ETHERNET, 0);
memset(&addr, 0x0, sizeof(struct wr_sockaddr));
memcpy(addr.mac, LLDP_MCAST_MAC, 6);
lldp_update();
}
static int lldp_poll(void) static int lldp_poll(void)
{ {
static int ticks; static int ticks;
...@@ -175,8 +184,9 @@ static int lldp_poll(void) ...@@ -175,8 +184,9 @@ static int lldp_poll(void)
if (ticks > LLDP_TX_FQ) { if (ticks > LLDP_TX_FQ) {
if (HAS_IP && (ip_status != IP_TRAINING)) { if (HAS_IP && (ip_status != IP_TRAINING)) {
lldp_add_tlv(PORT); //lldp_add_tlv(PORT);
lldp_add_tlv(MNG_ADD); lldp_add_tlv(MNG_ADD);
lldp_update();
/* update other dynamic TLVs */ /* update other dynamic TLVs */
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define IF_SUBTYPE 0x6 #define IF_SUBTYPE 0x6
#define IF_NUM 0x10 #define IF_NUM 0x10
#define LLDP_ID_SUBTYPE_MAC 3
#define LLDP_TX_FQ 1000 #define LLDP_TX_FQ 1000
enum TLV_TYPE { END_LLDP = 0, /* mandatory TLVs */ enum TLV_TYPE { END_LLDP = 0, /* mandatory TLVs */
...@@ -38,7 +40,7 @@ enum TLV_TYPE { END_LLDP = 0, /* mandatory TLVs */ ...@@ -38,7 +40,7 @@ enum TLV_TYPE { END_LLDP = 0, /* mandatory TLVs */
uint16_t tlv_type_len[TLV_MAX] = { 0x0, /* LEN_LLDP_END */ uint16_t tlv_type_len[TLV_MAX] = { 0x0, /* LEN_LLDP_END */
0x7, /* LEN_CHASSIS_ID */ 0x7, /* LEN_CHASSIS_ID */
0x14, /* LEN_PORT_ID */ 0x7, /* LEN_PORT_ID */
0x2, /* LEN_TTL */ 0x2, /* LEN_TTL */
0x14, /* LEN_PORT */ 0x14, /* LEN_PORT */
0x14, /* LEN_SYS_NAME */ 0x14, /* LEN_SYS_NAME */
...@@ -47,15 +49,4 @@ uint16_t tlv_type_len[TLV_MAX] = { 0x0, /* LEN_LLDP_END */ ...@@ -47,15 +49,4 @@ uint16_t tlv_type_len[TLV_MAX] = { 0x0, /* LEN_LLDP_END */
0xC /* LEN_MNG_ADD */ 0xC /* LEN_MNG_ADD */
}; };
uint16_t tlv_offset[TLV_MAX] = { 0x79, /* LEN_LLDP_END */
0x0, /* LEN_CHASSIS_ID */
0x9, /* LEN_PORT_ID */
0x1F, /* LEN_TTL */
0x23, /* LEN_PORT */
0x39, /* LEN_SYS_NAME */
0x4F, /* LEN_SYS_DESCR */
0x65, /* LEN_SYS_CAPLTY */
0x6B /* LEN_MNG_ADD */
};
#endif /* __LLDP_H */ #endif /* __LLDP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment