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
32
Issues
32
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
15e0cd25
Commit
15e0cd25
authored
Jan 14, 2016
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipv4: add a demo rdate service on UDP
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
77a288d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
ipv4.c
lib/ipv4.c
+41
-0
pfilter-builder.c
tools/pfilter-builder.c
+1
-0
No files found.
lib/ipv4.c
View file @
15e0cd25
...
...
@@ -7,10 +7,12 @@
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <string.h>
#include <wrpc.h>
#include "endpoint.h"
#include "ipv4.h"
#include "ptpd_netif.h"
#include "pps_gen.h"
#include "hw/memlayout.h"
#include "hw/etherbone-config.h"
...
...
@@ -37,6 +39,14 @@ static struct wrpc_socket __static_icmp_socket = {
};
static
struct
wrpc_socket
*
icmp_socket
;
/* RDATE: even smaller buffer -- but we require 86. 96 is "even". */
static
uint8_t
__rdate_queue
[
96
];
static
struct
wrpc_socket
__static_rdate_socket
=
{
.
queue
.
buff
=
__rdate_queue
,
.
queue
.
size
=
sizeof
(
__rdate_queue
),
};
static
struct
wrpc_socket
*
rdate_socket
;
unsigned
int
ipv4_checksum
(
unsigned
short
*
buf
,
int
shorts
)
{
...
...
@@ -66,6 +76,10 @@ void ipv4_init(void)
bootp_socket
=
ptpd_netif_create_socket
(
&
__static_bootp_socket
,
&
saddr
,
PTPD_SOCK_UDP
,
68
/* bootpc */
);
/* time (rdate): UDP */
rdate_socket
=
ptpd_netif_create_socket
(
&
__static_rdate_socket
,
&
saddr
,
PTPD_SOCK_UDP
,
37
/* time */
);
/* ICMP: specify raw (not UDP), with IPV4 ethtype */
saddr
.
ethertype
=
htons
(
0x0800
);
icmp_socket
=
ptpd_netif_create_socket
(
&
__static_icmp_socket
,
&
saddr
,
...
...
@@ -117,11 +131,38 @@ static void icmp_poll(void)
ptpd_netif_sendto
(
icmp_socket
,
&
addr
,
buf
,
len
,
0
);
}
static
void
rdate_poll
(
void
)
{
struct
wr_sockaddr
addr
;
uint64_t
secs
;
uint32_t
result
;
uint8_t
buf
[
32
];
int
len
;
len
=
ptpd_netif_recvfrom
(
rdate_socket
,
&
addr
,
buf
,
sizeof
(
buf
),
NULL
);
if
(
len
<=
0
)
return
;
shw_pps_gen_get_time
(
&
secs
,
NULL
);
result
=
htonl
((
uint32_t
)(
secs
+
2208988800LL
));
/* Magic above: $(date +%s --date="Jan 1 1900 00:00:00 UTC)" */
len
=
UDP_END
+
sizeof
(
result
);
memcpy
(
buf
+
UDP_END
,
&
result
,
sizeof
(
result
));
fill_udp
(
buf
,
len
,
NULL
);
ptpd_netif_sendto
(
rdate_socket
,
&
addr
,
buf
,
len
,
0
);
}
void
ipv4_poll
(
void
)
{
bootp_poll
();
icmp_poll
();
rdate_poll
();
}
void
getIP
(
unsigned
char
*
IP
)
...
...
tools/pfilter-builder.c
View file @
15e0cd25
...
...
@@ -409,6 +409,7 @@ void pfilter_init(int mode, char *fname)
pfilter_cmp
(
18
,
0x0044
,
0xffff
,
MOV
,
PORT_UDP_HOST
);
/* bootpc */
pfilter_cmp
(
18
,
0x013f
,
0xffff
,
OR
,
PORT_UDP_HOST
);
/* ptp event */
pfilter_cmp
(
18
,
0x0140
,
0xffff
,
OR
,
PORT_UDP_HOST
);
/* ptp general */
pfilter_cmp
(
18
,
0x0025
,
0xffff
,
OR
,
PORT_UDP_HOST
);
/* rdate */
/* The CPU gets those ports in a proper UDP frame, plus the previous selections */
pfilter_logic3
(
FRAME_FOR_CPU
,
FRAME_UDP
,
AND
,
PORT_UDP_HOST
,
OR
,
FRAME_FOR_CPU
);
...
...
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