Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
31
Issues
31
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
c9c30aab
Commit
c9c30aab
authored
Jul 04, 2017
by
Adam Wujek
💬
Committed by
Grzegorz Daniluk
Dec 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/lldp: get rid of tlv_offset
Signed-off-by:
Adam Wujek
<
adam.wujek@cern.ch
>
parent
8705ee3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
31 deletions
+32
-31
lldp.c
lib/lldp.c
+29
-19
lldp.h
lib/lldp.h
+3
-12
No files found.
lib/lldp.c
View file @
c9c30aab
...
...
@@ -33,10 +33,10 @@ static struct wr_sockaddr addr;
static
void
lldp_header_tlv
(
int
tlv_type
)
{
lldpdu_len
=
tlv_offset
[
tlv_type
];
lldpdu
[
lldpdu_len
]
=
tlv_type
*
2
;
//
lldpdu_len = tlv_offset[tlv_type];
lldpdu
[
lldpdu_len
]
=
tlv_type
<<
1
;
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
)
{
...
...
@@ -66,8 +66,9 @@ static void lldp_add_tlv(int tlv_type) {
lldp_header_tlv
(
tlv_type
);
/* TLV Interce Alias */
lldpdu
[
lldpdu_len
]
=
7
;
strcpy
(
lldpdu
+
(
lldpdu_len
+
LLDP_SUBTYPE
),
"WR Port"
);
lldpdu
[
lldpdu_len
]
=
LLDP_ID_SUBTYPE_MAC
;
get_mac_addr
(
mac
);
memcpy
(
lldpdu
+
(
lldpdu_len
+
LLDP_SUBTYPE
),
mac
,
6
);
break
;
case
TTL
:
/* header */
...
...
@@ -132,27 +133,18 @@ static void lldp_add_tlv(int tlv_type) {
break
;
case
USER_DEF
:
/* TODO define WR TLV */
return
;
break
;
default:
return
;
break
;
}
lldpdu_len
+=
tlv_type_len
[
tlv_type
];
}
static
void
lldp_
init
(
void
)
static
void
lldp_
update
(
void
)
{
struct
wr_sockaddr
saddr
;
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 */
memset
(
lldpdu
,
0x0
,
LLDP_PKT_LEN
);
lldpdu_len
=
0
;
...
...
@@ -167,6 +159,23 @@ static void lldp_init(void)
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
ticks
;
...
...
@@ -175,8 +184,9 @@ static int lldp_poll(void)
if
(
ticks
>
LLDP_TX_FQ
)
{
if
(
HAS_IP
&&
(
ip_status
!=
IP_TRAINING
))
{
lldp_add_tlv
(
PORT
);
//
lldp_add_tlv(PORT);
lldp_add_tlv
(
MNG_ADD
);
lldp_update
();
/* update other dynamic TLVs */
}
...
...
lib/lldp.h
View file @
c9c30aab
...
...
@@ -22,6 +22,8 @@
#define IF_SUBTYPE 0x6
#define IF_NUM 0x10
#define LLDP_ID_SUBTYPE_MAC 3
#define LLDP_TX_FQ 1000
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 */
0x7
,
/* LEN_CHASSIS_ID */
0x
14
,
/* LEN_PORT_ID */
0x
7
,
/* LEN_PORT_ID */
0x2
,
/* LEN_TTL */
0x14
,
/* LEN_PORT */
0x14
,
/* LEN_SYS_NAME */
...
...
@@ -47,15 +49,4 @@ uint16_t tlv_type_len[TLV_MAX] = { 0x0, /* LEN_LLDP_END */
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 */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment