Browse Source

Basic, functional-but-extremely-pessimal versions (taken from

uip-0.9/unix/uip_arch.c).
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
1c7c24f21f
1 changed files with 83 additions and 0 deletions
  1. 83
    0
      src/proto/uip/uip_arch.c

+ 83
- 0
src/proto/uip/uip_arch.c View File

@@ -0,0 +1,83 @@
1
+#include <stdint.h>
2
+#include <byteswap.h>
3
+#include "uip_arch.h"
4
+#include "uip.h"
5
+
6
+volatile u8_t uip_acc32[4];
7
+
8
+void uip_add32 ( u8_t *op32, u16_t op16 ) {
9
+	* ( ( uint32_t * ) uip_acc32 ) =
10
+		htonl ( ntohl ( *( ( uint32_t * ) op32 ) )  + op16 );
11
+}
12
+
13
+#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
14
+#define IP_PROTO_TCP    6
15
+
16
+u16_t uip_chksum(u16_t *sdata, u16_t len) {
17
+  u16_t acc;
18
+  
19
+  for(acc = 0; len > 1; len -= 2) {
20
+    acc += *sdata;
21
+    if(acc < *sdata) {
22
+      /* Overflow, so we add the carry to acc (i.e., increase by
23
+         one). */
24
+      ++acc;
25
+    }
26
+    ++sdata;
27
+  }
28
+
29
+  /* add up any odd byte */
30
+  if(len == 1) {
31
+    acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);
32
+    if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {
33
+      ++acc;
34
+    }
35
+  }
36
+
37
+  return acc;
38
+}
39
+
40
+u16_t uip_ipchksum(void) {
41
+  return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);
42
+}
43
+
44
+u16_t uip_tcpchksum(void) {
45
+  u16_t hsum, sum;
46
+
47
+  
48
+  /* Compute the checksum of the TCP header. */
49
+  hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);
50
+
51
+  /* Compute the checksum of the data in the TCP packet and add it to
52
+     the TCP header checksum. */
53
+  sum = uip_chksum((u16_t *)uip_appdata,
54
+		   (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40)));
55
+
56
+  if((sum += hsum) < hsum) {
57
+    ++sum;
58
+  }
59
+  
60
+  if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {
61
+    ++sum;
62
+  }
63
+  if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {
64
+    ++sum;
65
+  }
66
+  if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {
67
+    ++sum;
68
+  }
69
+  if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {
70
+    ++sum;
71
+  }
72
+  if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {
73
+    ++sum;
74
+  }
75
+
76
+  hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);
77
+  
78
+  if((sum += hsum) < hsum) {
79
+    ++sum;
80
+  }
81
+  
82
+  return sum;
83
+}

Loading…
Cancel
Save