Browse Source

The following edits were made: \

1. Updated UDP send data code\
2. Corrected internet checksum\
3. Moved udp_buffer() and udp_buflen() to udp.c from udp.h
tags/v0.9.3
Nikhil Chandru Rao 18 years ago
parent
commit
ab577e1a3a
4 changed files with 62 additions and 33 deletions
  1. 1
    1
      src/include/gpxe/tcpip_if.h
  2. 17
    5
      src/include/gpxe/udp.h
  3. 14
    25
      src/net/tcpip_if.c
  4. 30
    2
      src/net/udp.c

+ 1
- 1
src/include/gpxe/tcpip_if.h View File

83
 extern int trans_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip, 
83
 extern int trans_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip, 
84
 		      struct sockaddr *dest );
84
 		      struct sockaddr *dest );
85
 
85
 
86
-extern uint16_t calc_chksum ( void *data, size_t len );
86
+extern uint16_t calc_chksum ( void *b, int len );
87
 
87
 
88
 extern struct tcpip_protocol * find_tcpip_protocol ( uint8_t trans_proto );
88
 extern struct tcpip_protocol * find_tcpip_protocol ( uint8_t trans_proto );
89
 extern struct tcpip_net_protocol * find_tcpip_net_protocol ( sa_family_t sa_family );
89
 extern struct tcpip_net_protocol * find_tcpip_net_protocol ( sa_family_t sa_family );

+ 17
- 5
src/include/gpxe/udp.h View File

41
  *
41
  *
42
  */
42
  */
43
 struct udp_operations {
43
 struct udp_operations {
44
+	
45
+	/**
46
+	 * Transmit data
47
+	 *
48
+	 * @v conn	UDP connection
49
+	 * @v buf	Temporary data buffer
50
+	 * @v len	Length of temporary data buffer
51
+	 *
52
+	 * The application may use the temporary data buffer to
53
+	 * construct the data to be sent.  Note that merely filling
54
+	 * the buffer will do nothing; the application must call
55
+	 * udp_send() in order to actually transmit the data.  Use of
56
+	 * the buffer is not compulsory; the application may call
57
+	 * udp_send() on any block of data.
58
+	 */
59
+	void ( * senddata ) ( struct tcp_connection *conn, void *buf,
60
+			      size_t len );
44
 	/**
61
 	/**
45
 	 * New data received
62
 	 * New data received
46
 	 *
63
 	 *
69
 	struct udp_operations *udp_op;
86
 	struct udp_operations *udp_op;
70
 };
87
 };
71
 
88
 
72
-/**
73
- * List of registered UDP connections
74
- */
75
-static LIST_HEAD ( udp_conns );
76
-
77
 /**
89
 /**
78
  * UDP protocol
90
  * UDP protocol
79
  */
91
  */

+ 14
- 25
src/net/tcpip_if.c View File

107
 /**
107
 /**
108
  * Calculate internet checksum
108
  * Calculate internet checksum
109
  *
109
  *
110
- * @v data      Pointer to the data
111
- * @v len       Length of data to be checksummed
112
- * @ret chksum  16 bit internet checksum
113
- *
114
- * This function calculates the internet checksum (refer RFC1071) for "len"
115
- * bytes beginning at the location "data"
110
+ * @v b		Pointer to the data
111
+ * @v len	Length of data to be checksummed
112
+ * @ret result	16 bit internet checksum
116
  */
113
  */
117
-uint16_t calc_chksum ( void *data, size_t len ) {
118
-	register long sum = 0;
119
-	uint16_t checksum;
120
-	unsigned short *temp;
121
-	while ( len > 1 ) {
122
-		temp = (unsigned short*) data++;
123
-		sum += *temp;
124
-		len -= 2;
125
-	}
126
-	if ( len > 0 ) {
127
-		sum += *(unsigned char *)data;
128
-	}
129
-	while ( sum >> 16 ) {
130
-		sum = ( sum & 0xffff ) + ( sum >> 16 );
131
-	}
132
-	checksum = ~sum;
133
-	return checksum;
114
+uint16_t calc_chksum(void *b, int len) {
115
+	uint16_t *buf = b, result;
116
+	uint16_t sum=0;
117
+	for ( sum = 0; len > 1; len -= 2 ) /* Sum all 16b words */
118
+		sum += *buf++;
119
+	if ( len == 1 )                  /* If any stray bytes, */
120
+		sum += *(unsigned char*)buf;          /* add to sum */
121
+	sum = (sum >> 16) + (sum & 0xffff);    /* Add the carry */
122
+	sum += (sum >> 16);                          /* (again) */
123
+	result = ~sum;             /* Take the one's complement */
124
+	return result;                      /* Return 16b value */
134
 }
125
 }
135
-
136
-

+ 30
- 2
src/net/udp.c View File

18
  * UDP protocol
18
  * UDP protocol
19
  */
19
  */
20
 
20
 
21
+/**
22
+ * List of registered UDP connections
23
+ */
24
+static LIST_HEAD ( udp_conns );
25
+
26
+/**
27
+ * Some utility functions
28
+ */
21
 static inline void copy_sockaddr ( struct sockaddr *source, struct sockaddr *dest ) {
29
 static inline void copy_sockaddr ( struct sockaddr *source, struct sockaddr *dest ) {
22
 	memcpy ( dest, source, sizeof ( *dest ) );
30
 	memcpy ( dest, source, sizeof ( *dest ) );
23
 }
31
 }
98
 }
106
 }
99
 
107
 
100
 /**
108
 /**
101
- * Send data via a UDP connection
109
+ * User request to send data via a UDP connection
110
+ *
111
+ * @v conn	UDP connection
112
+ *
113
+ * This function allocates buffer space and invokes the function's senddata()
114
+ * callback. The callback may use the buffer space
115
+ */
116
+int udp_senddata ( struct udp_connection *conn ) {
117
+	conn->tx_pkb = pkb_alloc ( UDP_MAX_TXPKB );
118
+	if ( conn->tx_pkb == NULL ) {
119
+		DBG ( "Error allocating packet buffer of length %d\n",
120
+							UDP_MAX_TXPKB );
121
+		return -ENOMEM;
122
+	}
123
+	conn->udp_op->senddata ( conn, conn->tx_pkb, pkb_len ( conn->tx_pkb ) );
124
+	return 0;
125
+}
126
+		
127
+
128
+/**
129
+ * Transmit data via a UDP connection
102
  *
130
  *
103
  * @v conn      UDP connection
131
  * @v conn      UDP connection
104
  * @v data      Data to send
132
  * @v data      Data to send
124
 
152
 
125
 		/* Reserve space for the headers and copy contents */
153
 		/* Reserve space for the headers and copy contents */
126
 		pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
154
 		pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
127
-		memcpy ( pkb_put ( conn->tx_pkb, len ), data, len );
155
+		memmove ( pkb_put ( conn->tx_pkb, len ), data, len );
128
 	}
156
 	}
129
 
157
 
130
 	/*
158
 	/*

Loading…
Cancel
Save