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
50868480
Commit
50868480
authored
Jul 17, 2012
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tom-shell' of ohwr.org:hdl-core-lib/wr-cores/wrpc-sw into tom-shell
parents
8b0d60e5
3576653b
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
32 deletions
+44
-32
arp.c
lib/arp.c
+2
-0
bootp.c
lib/bootp.c
+1
-13
icmp.c
lib/icmp.c
+2
-0
ipv4.c
lib/ipv4.c
+34
-12
ipv4.h
lib/ipv4.h
+2
-2
ptp-noposix
ptp-noposix
+1
-1
cmd_ip.c
shell/cmd_ip.c
+2
-4
No files found.
lib/arp.c
View file @
50868480
...
...
@@ -32,10 +32,12 @@ void arp_init(const char* if_name) {
static
int
process_arp
(
uint8_t
*
buf
,
int
len
)
{
uint8_t
hisMAC
[
6
];
uint8_t
hisIP
[
4
];
uint8_t
myIP
[
4
];
if
(
len
<
ARP_END
)
return
0
;
/* Is it ARP request targetting our IP? */
getIP
(
myIP
);
if
(
buf
[
ARP_OPER
+
0
]
!=
0
||
buf
[
ARP_OPER
+
1
]
!=
1
||
memcmp
(
buf
+
ARP_TPA
,
myIP
,
4
))
...
...
lib/bootp.c
View file @
50868480
#include <string.h>
#include "ipv4.h"
#include "hw/memlayout.h"
#include "hw/etherbone-config.h"
#define IP_VERSION 0
#define IP_TOS (IP_VERSION+1)
...
...
@@ -126,9 +124,6 @@ int send_bootp(uint8_t* buf, int retry) {
int
process_bootp
(
uint8_t
*
buf
,
int
len
)
{
volatile
unsigned
int
*
eb_ip
=
(
unsigned
int
*
)(
BASE_ETHERBONE_CFG
+
EB_IPV4
);
unsigned
int
ip
;
uint8_t
mac
[
6
];
get_mac_addr
(
mac
);
...
...
@@ -144,14 +139,7 @@ int process_bootp(uint8_t* buf, int len)
if
(
memcmp
(
buf
+
BOOTP_CHADDR
,
mac
,
6
))
return
0
;
mprintf
(
"Discovered IP address!
\n
"
);
memcpy
(
myIP
,
buf
+
BOOTP_YIADDR
,
4
);
ip
=
(
buf
[
BOOTP_YIADDR
+
0
]
<<
24
)
|
(
buf
[
BOOTP_YIADDR
+
1
]
<<
16
)
|
(
buf
[
BOOTP_YIADDR
+
2
]
<<
8
)
|
(
buf
[
BOOTP_YIADDR
+
3
]);
while
(
*
eb_ip
!=
ip
)
*
eb_ip
=
ip
;
setIP
(
buf
+
BOOTP_YIADDR
);
return
1
;
}
lib/icmp.c
View file @
50868480
...
...
@@ -23,9 +23,11 @@
int
process_icmp
(
uint8_t
*
buf
,
int
len
)
{
int
iplen
,
hisBodyLen
;
uint8_t
hisIP
[
4
];
uint8_t
myIP
[
4
];
uint16_t
sum
;
/* Is it IP targetting us? */
getIP
(
myIP
);
if
(
buf
[
IP_VERSION
]
!=
0x45
||
memcmp
(
buf
+
IP_DEST
,
myIP
,
4
))
return
0
;
...
...
lib/ipv4.c
View file @
50868480
...
...
@@ -3,9 +3,11 @@
#include "endpoint.h"
#include "ipv4.h"
#include "ptpd_netif.h"
#include "hw/memlayout.h"
#include "hw/etherbone-config.h"
uint8_t
myIP
[
4
];
int
needIP
=
1
;
static
uint8_t
myIP
[
4
];
static
wr_socket_t
*
ipv4_socket
;
unsigned
int
ipv4_checksum
(
unsigned
short
*
buf
,
int
shorts
)
{
...
...
@@ -35,32 +37,52 @@ void ipv4_init(const char* if_name) {
ipv4_socket
=
ptpd_netif_create_socket
(
PTPD_SOCK_RAW_ETHERNET
,
0
,
&
saddr
);
}
void
ipv4_poll
(
void
)
{
static
int
retry
=
0
;
static
int
timer
=
0
;
static
int
bootp_retry
=
0
;
static
int
bootp_timer
=
0
;
void
ipv4_poll
(
void
)
{
uint8_t
buf
[
400
];
wr_sockaddr_t
addr
;
int
len
;
if
((
len
=
ptpd_netif_recvfrom
(
ipv4_socket
,
&
addr
,
buf
,
sizeof
(
buf
),
0
))
>
0
)
{
if
(
needIP
&&
process_bootp
(
buf
,
len
-
14
))
{
retry
=
0
;
needIP
=
0
;
timer
=
0
;
}
if
(
needIP
)
process_bootp
(
buf
,
len
-
14
);
if
(
!
needIP
&&
(
len
=
process_icmp
(
buf
,
len
-
14
))
>
0
)
ptpd_netif_sendto
(
ipv4_socket
,
&
addr
,
buf
,
len
,
0
);
}
if
(
needIP
&&
timer
==
0
)
{
len
=
send_bootp
(
buf
,
++
retry
);
if
(
needIP
&&
bootp_
timer
==
0
)
{
len
=
send_bootp
(
buf
,
++
bootp_
retry
);
memset
(
addr
.
mac
,
0xFF
,
6
);
addr
.
ethertype
=
htons
(
0x0800
);
/* IPv4 */
ptpd_netif_sendto
(
ipv4_socket
,
&
addr
,
buf
,
len
,
0
);
}
if
(
needIP
&&
++
timer
==
100000
)
timer
=
0
;
if
(
needIP
&&
++
bootp_timer
==
100000
)
bootp_timer
=
0
;
}
void
getIP
(
unsigned
char
*
IP
)
{
memcpy
(
IP
,
myIP
,
4
);
}
void
setIP
(
unsigned
char
*
IP
)
{
volatile
unsigned
int
*
eb_ip
=
(
unsigned
int
*
)(
BASE_ETHERBONE_CFG
+
EB_IPV4
);
unsigned
int
ip
;
memcpy
(
myIP
,
IP
,
4
);
ip
=
(
myIP
[
0
]
<<
24
)
|
(
myIP
[
1
]
<<
16
)
|
(
myIP
[
2
]
<<
8
)
|
(
myIP
[
3
]);
while
(
*
eb_ip
!=
ip
)
*
eb_ip
=
ip
;
needIP
=
(
ip
==
0
);
if
(
!
needIP
)
{
bootp_retry
=
0
;
bootp_timer
=
0
;
}
}
lib/ipv4.h
View file @
50868480
...
...
@@ -10,9 +10,9 @@ unsigned int ipv4_checksum(unsigned short* buf, int shorts);
void
arp_init
(
const
char
*
if_name
);
void
arp_poll
(
void
);
extern
uint8_t
myMAC
[
6
];
extern
uint8_t
myIP
[
4
];
extern
int
needIP
;
void
setIP
(
unsigned
char
*
IP
);
void
getIP
(
unsigned
char
*
IP
);
int
process_icmp
(
uint8_t
*
buf
,
int
len
);
int
process_bootp
(
uint8_t
*
buf
,
int
len
);
/* non-zero if IP was set */
...
...
ptp-noposix
@
45c029e5
Subproject commit
d04a278a9dc441984c8947e11395b7c6e39d83
25
Subproject commit
45c029e5fe5e64a75393b174d8e14780019164
25
shell/cmd_ip.c
View file @
50868480
...
...
@@ -22,12 +22,10 @@ int cmd_ip(const char *args[])
unsigned
char
ip
[
4
];
if
(
!
args
[
0
]
||
!
strcasecmp
(
args
[
0
],
"get"
))
{
/* get current IP */
memcpy
(
ip
,
myIP
,
4
);
getIP
(
ip
);
}
else
if
(
!
strcasecmp
(
args
[
0
],
"set"
)
&&
args
[
1
])
{
decode_ip
(
args
[
1
],
ip
);
memcpy
(
myIP
,
ip
,
4
);
needIP
=
!
ip
[
0
]
&&
!
ip
[
1
]
&&
!
ip
[
2
]
&&
!
ip
[
3
];
setIP
(
ip
);
}
else
{
return
-
EINVAL
;
}
...
...
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