Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
EtherBone Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
EtherBone Core
Commits
1f13ccd5
Commit
1f13ccd5
authored
Mar 01, 2013
by
Mathias Kreider
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed udp checksum bug
parent
fef253ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
19 deletions
+28
-19
etherbone.h
api/etherbone.h
+1
-1
lm32.c
api/transport/lm32.c
+27
-18
No files found.
api/etherbone.h
View file @
1f13ccd5
...
...
@@ -29,7 +29,7 @@
#ifndef ETHERBONE_H
#define ETHERBONE_H
#define DEBUG_EB
0
#define DEBUG_EB
1
#define EB_PROTOCOL_VERSION 1
#define EB_ABI_VERSION 0x02
/* incremented on incompatible changes */
...
...
api/transport/lm32.c
View file @
1f13ccd5
...
...
@@ -310,38 +310,47 @@ static uint16_t myIP_checksum(uint8_t *buf, int shorts)
return
(
uint16_t
)
sum
;
}
//Protocol header functions
static
uint16_t
udp_checksum
(
const
uint8_t
*
hdrbuf
,
const
uint8_t
*
databuf
,
uint16_t
len
)
{
//Prep udp checksum
int
i
;
uint32_t
sum
;
uint32_t
sum
,
pseudosum
,
tmp
;
sum
=
0
;
pseudosum
=
0
;
//calc chksum for data
for
(
i
=
0
;
i
<
(
len
&
0xfffe
);
++
i
)
sum
+=
(
databuf
[
i
+
0
]
<<
8
)
|
(
databuf
[
i
+
1
]);
dbgprint
(
"Len %4x
\n
"
,
len
);
if
(
len
&
0x01
)
sum
+=
databuf
[
i
];
// if len is odd, pad the last byte and add
//calc chksum for data
for
(
i
=
0
;
i
<
(
len
);
i
+=
2
)
{
tmp
=
((
uint32_t
)(
databuf
[
i
+
0
]
<<
8
)
&
0xFF00
)
|
((
uint32_t
)
databuf
[
i
+
1
]
&
0x00FF
);
sum
+=
tmp
;
}
if
(
len
&
0x01
)
sum
+=
(((
uint32_t
)
databuf
[
i
+
1
])
<<
8
);
// if len is odd, pad the last byte and add
//add pseudoheader
sum
+=
(
hdrbuf
[
IP_SPA
+
0
]
<<
8
)
|
(
hdrbuf
[
IP_SPA
+
1
]);
sum
+=
(
hdrbuf
[
IP_SPA
+
2
]
<<
8
)
|
(
hdrbuf
[
IP_SPA
+
3
]);
sum
+=
(
hdrbuf
[
IP_DPA
+
0
]
<<
8
)
|
(
hdrbuf
[
IP_DPA
+
1
]);
sum
+=
(
hdrbuf
[
IP_DPA
+
2
]
<<
8
)
|
(
hdrbuf
[
IP_DPA
+
3
]);
sum
+=
(
uint16_t
)
hdrbuf
[
IP_PROTO
];
pseudosum
+=
((
hdrbuf
[
IP_SPA
+
0
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
IP_SPA
+
1
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
IP_SPA
+
2
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
IP_SPA
+
3
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
IP_DPA
+
0
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
IP_DPA
+
1
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
IP_DPA
+
2
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
IP_DPA
+
3
])
&
0x00FF
);
pseudosum
+=
(
hdrbuf
[
IP_PROTO
]
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
UDP_SPP
+
0
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
UDP_SPP
+
1
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
UDP_DPP
+
0
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
UDP_DPP
+
1
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
UDP_LEN
+
0
]
<<
8
)
&
0xFF00
)
|
((
hdrbuf
[
UDP_LEN
+
1
])
&
0x00FF
);
pseudosum
+=
((
hdrbuf
[
UDP_CHKSUM
+
0
]
<<
8
)
&
0xFF00
)
|
(
hdrbuf
[
UDP_CHKSUM
+
1
]
&
0x00FF
);
sum
+=
(
hdrbuf
[
UDP_SPP
+
0
]
<<
8
)
|
(
hdrbuf
[
UDP_SPP
+
1
]);
sum
+=
(
hdrbuf
[
UDP_DPP
+
0
]
<<
8
)
|
(
hdrbuf
[
UDP_DPP
+
1
]);
sum
+=
(
hdrbuf
[
UDP_LEN
+
0
]
<<
8
)
|
(
hdrbuf
[
UDP_LEN
+
1
]);
sum
+=
(
hdrbuf
[
UDP_CHKSUM
+
0
]
<<
8
)
|
(
hdrbuf
[
UDP_CHKSUM
+
1
]);
//add carries and return complement
sum
+=
pseudosum
+
len
+
8
;
//add carries and return complement
sum
=
(
sum
>>
16
)
+
(
sum
&
0xffff
);
sum
+=
(
sum
>>
16
);
sum
+=
(
sum
>>
16
);
sum
=
(
~
sum
&
0xffff
);
dbgprint
(
"UDP inv %x
\n
"
,
sum
);
return
(
uint16_t
)
sum
;
}
...
...
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