PERFORCE change 123445 for review

Alexey Tarasov taleks at FreeBSD.org
Fri Jul 13 16:26:24 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=123445

Change 123445 by taleks at taleks_th on 2007/07/13 16:26:06

	all: style update
	printf.c: added sprintf()
	pxe_http: moved header retreiving to separate function.

Affected files ...

.. //depot/projects/soc2007/taleks-pxe_http/httpfs.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/httpfs.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/libstand_mod/printf.c#1 add
.. //depot/projects/soc2007/taleks-pxe_http/libstand_mod/stand.h#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#11 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#21 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#17 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.c#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#11 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#12 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.h#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.h#7 edit

Differences ...

==== //depot/projects/soc2007/taleks-pxe_http/httpfs.c#2 (text+ko) ====

@@ -7,8 +7,10 @@
 
 static int	http_open(const char *path, struct open_file *f);
 static int	http_close(struct open_file *f);
-static int	http_read(struct open_file *f, void *buf, size_t size, size_t *resid);
-static int	http_write(struct open_file *f, void *buf, size_t size, size_t *resid);
+static int	http_read(struct open_file *f, void *buf, size_t size,
+		    size_t *resid);
+static int	http_write(struct open_file *f, void *buf, size_t size,
+		    size_t *resid);
 static off_t	http_seek(struct open_file *f, off_t offset, int where);
 static int	http_stat(struct open_file *f, struct stat *sb);
 
@@ -41,12 +43,13 @@
 static int 
 http_open(const char *path, struct open_file *f)
 {
-	PXE_HTTP_HANDLE *httpfile = (PXE_HTTP_HANDLE *)malloc(sizeof(PXE_HTTP_HANDLE));
+	PXE_HTTP_HANDLE *httpfile =
+	    (PXE_HTTP_HANDLE *)malloc(sizeof(PXE_HTTP_HANDLE));
 	
 	if (!httpfile)
 		return (ENOMEM);
 
-	pxe_memeset(httpfile, 0, sizeof(PXE_HTTP_HANDLE));
+	pxe_memset(httpfile, 0, sizeof(PXE_HTTP_HANDLE));
 								
 	httpfile->ip = pxe_get_ip32(PXE_IP_WWW);
 	httpfile->offset = 0;

==== //depot/projects/soc2007/taleks-pxe_http/httpfs.h#2 (text+ko) ====

@@ -1,4 +1,8 @@
 #ifndef HTTPFS_INCLUDED
 #define HTTPFS_INCLUDED
 
+#include <stand.h>
+
+extern struct fs_ops http_fsops;
+
 #endif
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#11 (text+ko) ====

@@ -74,9 +74,7 @@
 		
 			uint8_t *mac = &arp_table[entry].mac[0];
 #ifdef PXE_DEBUG_HELL
-			printf("pxe_arp_table_search(): %2x:%2x:%2x:%2x:%2x:%2x\n",
-			    mac[0],  mac[1], mac[2], mac[3], mac[4], mac[5]
-			);
+			printf("pxe_arp_table_search(): %6D\n", mac, ":");
 #endif			
 			return (const MAC_ADDR *)mac;
 		}
@@ -115,8 +113,9 @@
 }
 
 /*
- *  pxe_arp_protocol() - process received arp packet, this function is called in style
- *                     of pxe_protocol_call function type, but last parameter is unused
+ *  pxe_arp_protocol() - process received arp packet, this function is called in
+ *			style of pxe_protocol_call function type, but last
+ *			parameter is unused
  *  in:
  *	pack     - rceived packet data
  *	function - protocal function (will be always PXE_CORE_FRAG)
@@ -141,7 +140,8 @@
 		ip4_src.ip = arp_reply->body.src_paddr;
 		ip4_dst.ip = arp_reply->body.target_paddr;
 		
-		if (ip4_src.ip == pxe_get_ip32(PXE_IP_MY)) { /* got broadcast send by us */
+		if (ip4_src.ip == pxe_get_ip32(PXE_IP_MY)) {
+			/* got broadcast send by us */
 #ifdef PXE_DEBUG_HELL
 			printf("arp request from myself ignored.\n");
 #endif
@@ -149,19 +149,28 @@
 		}
 		
 #ifdef PXE_DEBUG		
-		printf("arp request from %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n\t to: %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n",
-		    mac_src[0], mac_src[1], mac_src[2], mac_src[3], mac_src[4], mac_src[5],
-		    ip4_src.octet[0], ip4_src.octet[1], ip4_src.octet[2], ip4_src.octet[3],
-		    mac_dst[0], mac_dst[1], mac_dst[2], mac_dst[3], mac_dst[4], mac_dst[5],
-		    ip4_dst.octet[0], ip4_dst.octet[1], ip4_dst.octet[2], ip4_dst.octet[3]
+		printf("arp request from %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n\t"
+		    " to: %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n",
+		    mac_src[0], mac_src[1], mac_src[2],
+		    mac_src[3], mac_src[4], mac_src[5],
+		    ip4_src.octet[0], ip4_src.octet[1],
+		    ip4_src.octet[2], ip4_src.octet[3],
+		    mac_dst[0], mac_dst[1], mac_dst[2],
+		    mac_dst[3], mac_dst[4], mac_dst[5],
+		    ip4_dst.octet[0], ip4_dst.octet[1],
+		    ip4_dst.octet[2], ip4_dst.octet[3]
 		);
 #endif		
 
 		/* somebody is looking for us */
 		if (ip4_dst.ip == arp_table[MAX_ARP_ENTRIES].ip4.ip) {
 		
-			pxe_memcpy(arp_reply->body.src_hwaddr, packet_to_send.body.target_hwaddr, 6);
-			packet_to_send.body.target_paddr = arp_reply->body.src_paddr;
+			pxe_memcpy(arp_reply->body.src_hwaddr,
+			    packet_to_send.body.target_hwaddr, 6);
+			    
+			packet_to_send.body.target_paddr =
+			    arp_reply->body.src_paddr;
+			    
 			packet_to_send.hdr.operation = le2be16(PXE_ARPOP_REPLY);
 		
 			PXE_PACKET	pack;
@@ -169,9 +178,13 @@
 			pack.raw_size = sizeof(PXE_ARP_PACK_DATA);
 			pack.raw_data = &packet_to_send;
 			pack.data = &packet_to_send.hdr;
-			pack.data_size = sizeof(PXE_ARP_PACK_DATA) - MEDIAHDR_LEN_ETH;		
+			pack.data_size =
+			    sizeof(PXE_ARP_PACK_DATA) - MEDIAHDR_LEN_ETH;
+			    
 		    	pack.protocol = PXE_PROTOCOL_ARP;
-			pack.dest_mac = (const MAC_ADDR *)&packet_to_send.body.target_hwaddr[0];
+			pack.dest_mac = (const MAC_ADDR *)
+			    &packet_to_send.body.target_hwaddr[0];
+			    
 			pack.flags = PXE_SINGLE;
 		
 			if (!pxe_core_transmit(&pack)) {
@@ -191,15 +204,18 @@
 		return (0);		
 #endif
 	}
-
-	if (arp_reply->hdr.operation != le2be16(PXE_ARPOP_REPLY) ) /* we don't need anything except replies on that stage */
-		return (0); 
+	
+	/* we don't need anything except replies on that stage */
+	if (arp_reply->hdr.operation != le2be16(PXE_ARPOP_REPLY) ) 
+		return (0);
 		
-	/* if arp_usage exceeds MAX_ARP_ENTRIES, occurs rewriting of earlier placed ARP entries.
-	 * MAC may be lost, so protocol must check this case when creating packet (cause
-	 * there used pointer to MAC in arp_table). May be better way is to panic if arp_table
-	 * is full. In fact, we don't need many entries. Only two: one for gateway, one for DNS-server
-	 * or for proxy server. Default arp_table size is 8. It seems more than enough.
+	/* if arp_usage exceeds MAX_ARP_ENTRIES, occurs rewriting of earlier
+	 * placed ARP entries. MAC may be lost, so protocol must check this
+	 * case when creating packet (cause there used pointer to MAC
+	 * in arp_table). May be better way is to panic if arp_table is full.
+	 * In fact, we don't need many entries. Only two: one for gateway,
+	 * one for DNS-server or for proxy server. Default arp_table size is 8.
+	 * It seems more than enough.
 	 */	
 	 
 	const MAC_ADDR *kmac = pxe_arp_table_search(arp_reply->body.src_paddr);
@@ -208,15 +224,20 @@
 	        uint8_t *octet = (uint8_t *)&arp_reply->body.src_paddr;
 	        printf("MAC of %d.%d.%d.%d already known: %x:%x:%x:%x:%x:%x\n",
 		    octet[0], octet[1], octet[2], octet[3],
-		    (*kmac)[0], (*kmac)[1], (*kmac)[2], (*kmac)[3], (*kmac)[4], (*kmac)[5]
+		    (*kmac)[0], (*kmac)[1], (*kmac)[2],
+		    (*kmac)[3], (*kmac)[4], (*kmac)[5]
 		);
 #endif
-		/* NOTE: theoretically it's possible mac != known mac. Ignore for now. */
+		/* NOTE: theoretically it's possible mac != known mac. Ignore. */
 		return (0);
 	}
 	
-	pxe_memcpy(&arp_reply->body.src_hwaddr, &arp_table[arp_usage % MAX_ARP_ENTRIES].mac, 6);
-	arp_table[arp_usage % MAX_ARP_ENTRIES].ip4.ip = arp_reply->body.src_paddr;
+	pxe_memcpy(&arp_reply->body.src_hwaddr,
+	    &arp_table[arp_usage % MAX_ARP_ENTRIES].mac, 6);
+	    
+	arp_table[arp_usage % MAX_ARP_ENTRIES].ip4.ip =
+	    arp_reply->body.src_paddr;
+	    
 	++arp_usage;
 
 #ifdef PXE_DEBUG_HELL	
@@ -227,8 +248,8 @@
 }
 
 /*
- *  pxe_arp_send_whois() - sends ARP request packet for given ip, received packets are
- *                         handled in pxe_arp_protocol()
+ *  pxe_arp_send_whois() - sends ARP request packet for given ip, received
+ *			  packets are handled in pxe_arp_protocol()
  *  in:
  *	ip	- target ip, for which to find MAC
  *  out:
@@ -270,24 +291,28 @@
  *	PXE_AWAIT_ constants
  */
 int
-pxe_arp_await(uint8_t function, uint16_t try_number, uint32_t timeout, void *data)
+pxe_arp_await(uint8_t function, uint16_t try_number, uint32_t timeout,
+	      void *data)
 {
 	PXE_ARP_WAIT_DATA	*wait_data = (PXE_ARP_WAIT_DATA *)data;
 	const MAC_ADDR		*res = NULL;
 	switch (function) {
 
-	case PXE_AWAIT_STARTTRY:				/* handle start of new try */
-		if (pxe_arp_send_whois(wait_data->ip) != 1) {	/* failed to send request, try once more */
-			delay(10000);				/* after waiting a little */
+	case PXE_AWAIT_STARTTRY:	/* handle start of new try */
+		if (pxe_arp_send_whois(wait_data->ip) != 1) {	
+			/* failed to send request, try once more
+			 * after waiting a little
+			 */
+			delay(10000);				
 		        return (PXE_AWAIT_NEXTTRY);
 		}
 		break;
 
 	case PXE_AWAIT_NEWPACKETS:
-		
-		res = pxe_arp_table_search(wait_data->ip);	/* check if ARP protocol was called and 
-								 * arp_table updated 
-								 */
+		/* check if ARP protocol was called and 
+		 * arp_table updated 
+		 */
+		res = pxe_arp_table_search(wait_data->ip);	
 		if (res != NULL) {
 			wait_data->mac = res;
 			return (PXE_AWAIT_COMPLETED);
@@ -297,11 +322,11 @@
 		break;		
 
 	case PXE_AWAIT_FINISHTRY:
-		if (wait_data->mac == NULL)		/* nothing got during try */
+		if (wait_data->mac == NULL) 	/* nothing got during try */
 			printf("\npxe_arp_await(): ARP reply timeout.\n");
 		break;	
 
-	case PXE_AWAIT_END:				/* wait ended */
+	case PXE_AWAIT_END:			/* wait ended */
 	default:
 		break;
 	}
@@ -333,8 +358,7 @@
 	wait_data.ip = ip;
 	wait_data.mac = NULL;
 	
-	if (!pxe_await(pxe_arp_await, PXE_MAX_ARP_TRY, PXE_TIME_TO_DIE, &wait_data)) {
-	}
+	pxe_await(pxe_arp_await, PXE_MAX_ARP_TRY, PXE_TIME_TO_DIE, &wait_data);
 
 	pxe_core_exclusive(0);
 	

==== //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#2 (text+ko) ====

@@ -43,18 +43,25 @@
 #ifdef PXE_DEBUG
 			twiddle();
 #endif
-        	        if (pxe_core_recv_packets()) {          /* means some packet was received */
+        	        if (pxe_core_recv_packets()) {
+				/* means some packet was received */
                 	        
-				result = await_func(PXE_AWAIT_NEWPACKETS, try_counter, time_elapsed, data); 
+				result = await_func(PXE_AWAIT_NEWPACKETS,
+					    try_counter, time_elapsed, data); 
 
 				if (result == PXE_AWAIT_COMPLETED) {
-					await_func(PXE_AWAIT_FINISHTRY, try_counter, time_elapsed, data);
+					await_func(PXE_AWAIT_FINISHTRY,
+					    try_counter, time_elapsed, data);
+					    
 					return (1);
 				}
 				
-				if (result == PXE_AWAIT_NEXTTRY) {
+				if (result == PXE_AWAIT_NEXTTRY)
+					break;
+				
+				/* aborted waiting */
+				if (result == PXE_AWAIT_BREAK)
 					break;
-				}
 					
 				/* continue */		
 			}
@@ -64,7 +71,8 @@
 		}
 
 		/* notify about end of try */
-		result = await_func(PXE_AWAIT_FINISHTRY, try_counter, time_elapsed, data);
+		result = await_func(PXE_AWAIT_FINISHTRY, try_counter,
+			    time_elapsed, data);
 		
 		if (result == PXE_AWAIT_BREAK)	/* failure */
 			return (0);
@@ -76,7 +84,9 @@
 	/* notify about end of await, result is not interesting */
 	await_func(PXE_AWAIT_END, try_counter, time_elapsed, data);
 	
-	/* if waiting of packet successful, control returned higher (PXE_AWAIT_COMPLETED) */
+	/* if waiting of packet successful,
+	 * control returned higher (PXE_AWAIT_COMPLETED)
+	 */
 	return (0);
 }
 																														     
==== //depot/projects/soc2007/taleks-pxe_http/pxe_await.h#3 (text+ko) ====

@@ -4,24 +4,26 @@
 #include <stdint.h>
 
 /* await callback function type */
-typedef int (*pxe_await_func)(uint8_t function, uint16_t try_counter, uint32_t timeout,  void *data);
+typedef int (*pxe_await_func)(uint8_t function, uint16_t try_counter,
+		uint32_t timeout,  void *data);
 
-#define PXE_AWAIT_NEWPACKETS	0x00		/* some packets received, check it */
-#define PXE_AWAIT_STARTTRY	0x01		/* start of new try */
-#define PXE_AWAIT_FINISHTRY	0x02		/* end of current try */
-#define PXE_AWAIT_END		0x03		/* ending of waiting */
+#define PXE_AWAIT_NEWPACKETS	0x00	/* some packets received, check it */
+#define PXE_AWAIT_STARTTRY	0x01	/* start of new try */
+#define PXE_AWAIT_FINISHTRY	0x02	/* end of current try */
+#define PXE_AWAIT_END		0x03	/* ending of waiting */
 
 /* values that may be returned by await function */
-#define PXE_AWAIT_OK		0x00		/* ok, do what you want */
-#define PXE_AWAIT_COMPLETED	0x01		/* wait ended succefully */
-#define PXE_AWAIT_CONTINUE	0x02		/* continue waiting */
-#define PXE_AWAIT_NEXTTRY	0x03		/* continue with next try */
-#define PXE_AWAIT_BREAK		0x04		/* wait ended with failure */
+#define PXE_AWAIT_OK		0x00	/* ok, do what you want */
+#define PXE_AWAIT_COMPLETED	0x01	/* wait ended succefully */
+#define PXE_AWAIT_CONTINUE	0x02	/* continue waiting */
+#define PXE_AWAIT_NEXTTRY	0x03	/* continue with next try */
+#define PXE_AWAIT_BREAK		0x04	/* wait ended with failure */
 
 #define TIME_DELTA_MS		10
 #define TIME_DELTA		10000
 
 /* universal waiting function */
-int pxe_await(pxe_await_func func, uint16_t try_counter, uint32_t timeout, void *data);
+int pxe_await(pxe_await_func func, uint16_t try_counter,
+	uint32_t timeout, void *data);
 
 #endif

==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#6 (text+ko) ====

@@ -15,8 +15,9 @@
 	uint16_t	to_write = (size < buf->bufleft) ? size : buf->bufleft;
 
 #ifdef PXE_DEBUG_HELL
-	printf("pxe_buffer_write(): fstart %d, fend %d, bufleft %d (of %d), to_write %d (%d)\n",
-	    buf->fstart, buf->fend, buf->bufleft, buf->bufsize, to_write, size);
+	printf("pxe_buffer_write(): fstart %d, fend %d, bufleft %d (of %d),"
+	       " to_write %d (%d)\n", buf->fstart, buf->fend, buf->bufleft,
+	       buf->bufsize, to_write, size);
 #endif			
 
 	if (to_write == 0)	/* no space left*/
@@ -36,7 +37,8 @@
 		uint16_t part2 = to_write - part1;
 
 		if (part1)
-			pxe_memcpy(from, buf->data + buf->fstart, (part1 < to_write) ? part1 : to_write);
+			pxe_memcpy(from, buf->data + buf->fstart,
+			    (part1 < to_write) ? part1 : to_write);
 
 		if (part1 >= to_write) {
 			buf->fstart += to_write;
@@ -57,7 +59,8 @@
 /* pxe_buffer_read() - reades data from buffer, if possible
  * in:
  *	buf	- pointer to buffer structure
- *	to	- pointer to data to read to, if NULL data is read but not placed anywhere
+ *	to	- pointer to data to read to,
+ *		  if NULL - data is read but not placed anywhere
  *	size	- size of data buffer
  * out:
  *	actual count of read bytes
@@ -68,9 +71,9 @@
 	uint16_t	usage = buf->bufsize - buf->bufleft;
 	uint16_t	to_read = (size <= usage) ? size : usage;
 	
-	if (to_read == 0) {	/* nothing to read */
+	if (to_read == 0)	/* nothing to read */
 		return (0);
-	}
+	
 	
 	uint16_t fstart = buf->fstart;
 	uint16_t fend = buf->fend;
@@ -84,11 +87,12 @@
 		uint16_t part2 = to_read - part1;
 
 		if (part1 && (to != NULL) )
-			pxe_memcpy(buf->data + fend, to, (part1 < to_read) ? part1 : to_read);
+			pxe_memcpy(buf->data + fend, to,
+			    (part1 < to_read) ? part1 : to_read);
 		
-		if (part1 >= to_read) {
+		if (part1 >= to_read)
 			buf->fend += to_read;
-		} else {
+		else {
 			if (to != NULL)
 				pxe_memcpy(buf->data, to + part1, part2);
 			
@@ -123,7 +127,7 @@
 pxe_buffer_space(PXE_BUFFER *buffer)
 {
 
-	return buffer->bufleft;
+	return (buffer->bufleft);
 }
 
 /* pxe_buffer_memalloc() - allocates memory for buffer
@@ -168,9 +172,8 @@
 pxe_buffer_memfree(PXE_BUFFER *buffer)
 {
 
-	if (buffer->data == NULL) { /* already released */
+	if (buffer->data == NULL)  /* already released */
 		return;
-	}
 
 #ifdef PXE_DEBUG_HELL
 	printf("pxe_buffer_memfree(): buffer 0x%x, data 0x%x, bufleft: %d.\n",

==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#6 (text+ko) ====

@@ -3,14 +3,14 @@
 
 #include <stdint.h>
 
-/* buffer size choosed by default for sending/recieving*/
+/* buffer size choosed by default for sending/recieving */
 #define PXE_DEFAULT_RECV_BUFSIZE	32768
 #define PXE_DEFAULT_SEND_BUFSIZE        4096
 
 /* pxe_buffer - buffer related information */
 typedef struct pxe_buffer {
 
-	void        *data;      /* pointer to memory block, used for buffer*/
+	void        *data;      /* pointer to memory block, used for buffer */
 
 	uint16_t    fstart;	/* start of free space part in buffer */
 	uint16_t    fend;	/* end of free space part in buffer */

==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#8 (text+ko) ====

@@ -15,9 +15,11 @@
 /* currently allocated connections */
 static int                      all_connections = 0;
 
-/* filter_to_connection() - returns connections, associated with provided filter
+/* filter_to_connection() - returns connections,
+ *			    associated with provided filter
  * in:
- *	filter - pointer to filter entry structure, for which connection is searched
+ *	filter - pointer to filter entry structure,
+ *		for which connection is searched
  * out:
  *	NULL	- failed to find
  *	not NULL- searched connections
@@ -29,9 +31,8 @@
 	
 	for ( ; con_index < PXE_MAX_TCP_CONNECTIONS; ++con_index) {
 
-		if (tcp_connections[con_index].filter == filter) {
+		if (tcp_connections[con_index].filter == filter)
 			return (&tcp_connections[con_index]);
-		}
 	}
 
 	return (NULL);
@@ -67,7 +68,8 @@
 
 /* free_connection() - releases connections
  * in:
- *	connection - pointer to connection to release (assuming it's valid connection)
+ *	connection - pointer to connection to release
+ *		(assuming it's valid connection)
  * out:
  *	none
  */
@@ -91,7 +93,8 @@
 	PXE_TCP_CONNECTION *conn = wait_data->connection;
 	
         switch(function) {
-	        case PXE_AWAIT_NEWPACKETS:	/* check current state with needed to wait for */
+	        case PXE_AWAIT_NEWPACKETS:
+			/* check current state with needed to wait for */
 
 			if (wait_data->state <= conn->state)
 				return (PXE_AWAIT_COMPLETED);
@@ -118,7 +121,8 @@
 	return (PXE_AWAIT_OK);
 }
 
-/* pxe_tcp_connect() - connects TCP socket (performs handshaking). Blocks until handshaking is done.
+/* pxe_tcp_connect() - connects TCP socket (performs handshaking).
+ *			Blocks until handshaking is done.
  * in:
  *	socket - socket
  * out:
@@ -137,9 +141,8 @@
 	PXE_FILTER_ENTRY	*filter = sock->filter;	
 	PXE_TCP_CONNECTION	*connection = alloc_connection();
 
-	if (connection == NULL) {
+	if (connection == NULL)
 		return (0);
-	}
 	
 	pxe_memset(connection, 0, sizeof(PXE_TCP_CONNECTION));
 			
@@ -149,7 +152,9 @@
 	connection->next_recv = 0;
 	
 	/* NOTE: need to make more correct initial number */
-	connection->iss = (filter->src_ip + filter->dst_ip) + (uint32_t)pxe_get_secs();
+	connection->iss = (filter->src_ip + filter->dst_ip) +
+			  (uint32_t)pxe_get_secs();
+			  
 	connection->next_send = connection->iss;
 	
 	connection->filter = filter;
@@ -178,7 +183,8 @@
 	 * connection will fell in this state in pxe_tcp_callback(),
 	 * after receiving SYN ACK and sending ACK to remote host
 	 */
-	if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) { /* failed to get SYN/ACK */
+	if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) {
+		/* failed to get SYN/ACK */
 	    	free_connection(connection);
 		return (0);
 	}
@@ -211,9 +217,8 @@
 	
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(filter);
 
-	if (connection == NULL) {
+	if (connection == NULL)
 		return (0);
-	}
 
 	/* process recieved,  queued but not processed packets.
 	 * This is useful if server requested breaking of connection
@@ -230,7 +235,6 @@
 	}
 	
 	if (!pxe_tcp_syssend(connection, PXE_TCP_FIN | PXE_TCP_ACK)) { 
-/*	if (!pxe_tcp_syssend(connection, PXE_TCP_FIN)) { */
 		printf("pxe_tcp_disconnect(): failed to send FIN.\n");
 		free_connection(connection);
 		return (0);
@@ -259,17 +263,16 @@
 	/* awaiting expected state to close connection
 	 * connection will fell in this state in pxe_tcp_callback()
 	 */
-	if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) { /* failed to get expected state */
-
+	if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) {
+		/* failed to get expected state */
 	    	free_connection(connection);
 	
 		if (connection->state != PXE_TCP_CLOSED)
 			return (0);
 	}
 
-	if (connection->state == PXE_TCP_CLOSED) {
+	if (connection->state == PXE_TCP_CLOSED)
 		pxe_filter_remove(filter);
-	}
 			
 	pxe_resend_free(connection);
 	
@@ -306,7 +309,8 @@
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(sock->filter);
 
 	if (connection == NULL) {
-		printf("pxe_tcp_write(): no connection for filter 0x%x (socket: 0x%x).\n", sock->filter, sock);
+		printf("pxe_tcp_write(): no connection for filter 0x%x "
+		       "(socket: 0x%x).\n", sock->filter, sock);
 		return (-1);
 	}
 	
@@ -339,7 +343,8 @@
 			connection->segment = segment;
 			segment_data = (void *)(segment + 1);
 			
-			tcp_start_segment(connection, segment, PXE_SEGMENT_OPTS_NO);
+			tcp_start_segment(connection, segment,
+			    PXE_SEGMENT_OPTS_NO);
 		}
 		
 		/* calculating free space in segment packet */
@@ -349,18 +354,24 @@
 		send_now = size_to_send - sent_data;
 
 		if (send_now < bufleft) {
-			/* copy data to segment space, actually there is no send, till
-			 * segment is fully filled or called pxe_tcp_push()
+			/* copy data to segment space, actually there is no send,
+			 * till segment is fully filled or called pxe_tcp_push()
 			 */
-			pxe_memcpy(data + sent_data, segment_data + segment->size, send_now);
+			pxe_memcpy(data + sent_data,
+			    segment_data + segment->size, send_now);
+			    
 			segment->size += send_now;
 			sent_data += send_now;
 			
 			return (sent_data);
 		}
 		
-		/* if we got here, then we need to finish current segment and alloc new segment */
-		pxe_memcpy(data + sent_data, segment_data + segment->size, bufleft);
+		/* if we got here, then we need to finish current segment
+		 * and alloc new segment
+		 */
+		pxe_memcpy(data + sent_data,
+		    segment_data + segment->size, bufleft);
+		    
 		segment->size += bufleft;
 		sent_data += bufleft;
 		
@@ -373,7 +384,9 @@
     
 		if (!pxe_tcp_send_segment(connection, segment)) {
 			printf("pxe_tcp_write(): failed to send segment.\n");
-			/* this segment will be resent later, so continue normal processing */
+			/* this segment will be resent later,
+			 * so continue normal processing
+			 */
 		}
 		
 		pxe_core_recv_packets();
@@ -399,7 +412,8 @@
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(sock->filter);
 
 	if (connection == NULL) {
-		printf("pxe_tcp_read(): no connection for filter 0x%x (socket: 0x%x).\n", sock->filter, sock);
+		printf("pxe_tcp_read(): no connection for filter 0x%x "
+		       "(socket: 0x%x).\n", sock->filter, sock);
 		return (-1);
 	}
 
@@ -415,15 +429,17 @@
 
 	if (result != 0) { 
 
-		/* if receive window was zero and now is big enough, notify remote host */
+		/* if receive window was zero and now is big enough,
+		 * notify remote host
+		 */
 		if ( (connection->winlock == 1) &&
 		     (recv_buffer->bufleft > PXE_DEFAULT_RECV_BUFSIZE / 4))
 		{
-			if (!pxe_tcp_syssend(connection, PXE_TCP_ACK)) {
-				printf("pxe_tcp_read(): failed to notify remote host about window.\n");
-			} else {
+			if (!pxe_tcp_syssend(connection, PXE_TCP_ACK))
+				printf("pxe_tcp_read(): failed to notify "
+				       "remote host about window.\n");
+			else
 				connection->winlock = 0;
-			}
 		}
 	}
 	
@@ -447,7 +463,9 @@
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(filter);
 
 	if (connection == NULL) {
-		printf("pxe_tcp_push(): no connection for filter 0x%x.\n", filter);
+		printf("pxe_tcp_push(): no connection for filter 0x%x.\n",
+		    filter);
+		    
 		return (0);
 	}
 
@@ -455,16 +473,15 @@
 	     (connection->state != PXE_TCP_CLOSE_WAIT) )
 	{
 		printf("pxe_tcp_push(): connection 0x%x is in wrong state %d.\n",
-		    connection, connection->state
-		);
-		return (0);	/* connection not in established state, ignore available data */
+		    connection, connection->state);
+		/* connection not in established state, ignore available data */
+		return (0);	
 	}
 	
 	PXE_TCP_QUEUED_SEGMENT	*segment = connection->segment;
 	
-	if (segment == NULL) {	/* nothing to push */
+	if (segment == NULL)	/* nothing to push */
 		return (1);
-	}
 
 	/* finish segment */
 	tcp_finish_segment(connection, segment, PXE_TCP_ACK | PXE_TCP_PSH);
@@ -474,7 +491,9 @@
 	
 	if (!pxe_tcp_send_segment(connection, segment)) {
 		printf("pxe_tcp_push(): failed to send segment.\n");
-		/* this segment will be resent later, so continue normal processing */
+		/* this segment will be resent later,
+		 * so continue normal processing
+		 */
 	}
 
 	segment = NULL;
@@ -484,7 +503,8 @@
 }
 
 /* pxe_tcp_check_connection() - checks connections state by sending ACK,
- *				used e,g, to notify remote host about enough window to recv
+ *				used e.g. to notify remote host about
+ *				enough window to recv
  * in:
  *      sock		- TCP socket to check connection for
  * out:
@@ -500,25 +520,24 @@
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(sock->filter);
 
 	if (connection == NULL) {
-		printf("pxe_tcp_check_connection(): no connection for filter 0x%x (socket: 0x%x).\n",
-		    sock->filter, sock
-		);
+		printf("pxe_tcp_check_connection(): no connection for filter "
+		       "0x%x (socket: 0x%x).\n", sock->filter, sock);
 		return (0);
 	}
 
 	if (connection->state != PXE_TCP_ESTABLISHED) {
-		printf("pxe_tcp_check_connection(): connection 0x%x is not in established state(%d).\n",
-		    connection, connection->state
-		);
-		return (0);	/* connection not in established state, ignore available data */
+		printf("pxe_tcp_check_connection(): connection 0x%x "
+		       "is not in established state(%d).\n",
+		       connection, connection->state);
+		/* connection not in established state, ignore available data */
+		return (0);	
 	}
 	
 	PXE_BUFFER *buffer = connection->recv;
 	
 	/* send ACK ony if we place enough space */
-	if (buffer->bufleft < buffer->bufsize / 3) {
+	if (buffer->bufleft < buffer->bufsize / 3)
 		return (0);
-	}
 	
 	if (!pxe_tcp_syssend(connection, PXE_TCP_ACK)) {
 		printf("pxe_tcp_check_connection(): failed to send ACK.\n");
@@ -528,6 +547,10 @@
 	return (1);
 }
 
+/* pxe_connection_stats() - shows brief information about connections
+ * in/out:
+ * 	none
+ */
 void
 pxe_connection_stats()
 {
@@ -540,9 +563,9 @@
 
 		connection = &tcp_connections[con_index];
 		
-		printf("%d: filter: 0x%x, state: %d\n  nxt_snd: %d, nxt_rcv: %d, iss: %d, irs: %d\n",
-		    con_index, connection->filter, connection->state,
-		    connection->next_send, connection->next_recv
-		);
+		printf("%d: filter: 0x%x, state: %d\n"
+		       "  nxt_snd: %d, nxt_rcv: %d, iss: %d, irs: %d\n",
+		       con_index, connection->filter, connection->state,
+		       connection->next_send, connection->next_recv);
 	}
 }

==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#6 (text+ko) ====

@@ -7,17 +7,19 @@
 #include "pxe_filter.h"
 #include "pxe_sock.h"
 
+/* maximum existing connections at one time */
+#define PXE_MAX_TCP_CONNECTIONS 8
+
 /* connection states */
 #define PXE_TCP_STATE_MASK      0x0f
 
 #define PXE_TCP_CLOSED          0x00    /* closed */
-#define PXE_TCP_RESETED         0x0f    /* TODO: check if this needed.(received RST) */
 
 #define PXE_TCP_SYN_SENT        0x01    /* active */
 #define PXE_TCP_SYN_RECEIVED    0x02    /* sent & received SYN */
 #define PXE_TCP_ESTABLISHED     0x03    /* established connection */
 #define PXE_TCP_CLOSE_WAIT      0x04    /* got FIN, waiting to close */
-#define PXE_TCP_LAST_ACK        0x05    /* got FIN, closing and waiting FIN ACK */
+#define PXE_TCP_LAST_ACK        0x05    /* got FIN, closing & waiting FIN ACK */
 
 #define PXE_TCP_FIN_WAIT1       0x06    /* CLOSE, sent FIN */
 #define PXE_TCP_CLOSING         0x07    /* got FIN, sent ACK, waiting FIN ACK */
@@ -31,10 +33,11 @@
 typedef struct pxe_tcp_connecton {
 
     uint8_t     state;          /* current TCP conenction state */
-    uint8_t     state_out;      /* show latest acked packet flags (e.g. we sent FIN and it was ACKed,
-				 * here will be PXE_TCP_FIN. Currently used but ACKing not checked.
+    uint8_t     state_out;      /* show latest acked packet flags
+				 * (e.g. we sent FIN and it was ACKed,
+				 * here will be PXE_TCP_FIN.
 				 */
-    uint8_t	winlock;	/* flag to becomes 1 when recieve window is zero*/
+    uint8_t	winlock;	/* flag becomes 1 when recieve window is zero*/
     uint32_t    next_recv;      /* next sequence number to accept */
     uint32_t    next_send;      /* next sequence number to send */
     uint32_t    una;            /* unaccepted sequence number */

==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#21 (text+ko) ====

@@ -60,12 +60,13 @@
 	int status = pxe_core_call(PXENV_UNDI_STARTUP);
 	
 	if (!status)
-		printf("pxe_core_undi_startup(): status 0x%x\n", undi_startup->Status);	
+		printf("pxe_core_undi_startup(): status 0x%x\n",
+		    undi_startup->Status);
 
         return (status);
 }
 
-/* pxe_core_undi_init() - performs UNDI initialization  call during pxe_core_init()
+/* pxe_core_undi_init() - performs UNDI initialization
  * in:
  *	none
  * out:
@@ -86,7 +87,8 @@
 	int status = pxe_core_call(PXENV_UNDI_INITIALIZE);
 	
 	if (!status)
-		printf("pxe_core_undi_init(): status 0x%x\n", undi_init->Status);	
+		printf("pxe_core_undi_init(): status 0x%x\n",
+		    undi_init->Status);
 
 	return (status);
 }
@@ -103,7 +105,8 @@
 pxe_core_init(pxenv_t *pxenv_p, pxe_t* pxe_p)
 {
 #ifdef PXE_DEBUG
-	printf("pxe_core_init(): started (pxenv_p = 0x%x, pxe_p = 0x%x).\n", pxenv_p, pxe_p);
+	printf("pxe_core_init(): started (pxenv_p = 0x%x, pxe_p = 0x%x).\n",
+	    pxenv_p, pxe_p);
 #endif
 	int     counter = 0;
 	uint8_t checksum = 0;
@@ -144,8 +147,10 @@
 	 */
 	checksum = 0;
 	checkptr = (uint8_t *) pxenv_p;
+
 	for (counter = 0; counter < pxenv_p->Length; counter++)
 		checksum += *checkptr++;
+
 	if (checksum != 0) {
 		printf("PXENV+ structure failed checksum, ignoring\n");
 		pxenv_p = NULL;
@@ -161,20 +166,24 @@
 	 * the checksum fails.
 	 */
 	if (pxenv_p->Version >= 0x0200) {
+
 		for (;;) {
 			if (bcmp((void *)pxe_p->Signature, S_SIZE("!PXE"))) {
 				pxe_p = NULL;
 				break;
 			}
+			
 			checksum = 0;
 			checkptr = (uint8_t *)pxe_p;
+			
 			for (counter = 0; counter < pxe_p->StructLength;
 			     counter++)
 				checksum += *checkptr++;
+				
 			if (checksum != 0) {
 				pxe_p = NULL;
-				break;
 			}
+			
 			break;
 		}
 	}
@@ -184,7 +193,7 @@
 	       (uint8_t) (pxenv_p->Version >> 8),
 	       (uint8_t) (pxenv_p->Version & 0xFF));
 
-	printf(" @%04x:%04x\n",
+	printf(" @ %04x:%04x\n",
 	       pxe_p->EntryPointSP.segment,
 	       pxe_p->EntryPointSP.offset);
 
@@ -213,7 +222,8 @@
 	}
 
 #ifdef PXE_DEBUG
-	printf("pxe_core_init(): copied %d bytes of cached packet. Limit = %d.\n", gci_p->BufferSize, gci_p->BufferLimit);
+	printf("pxe_core_init(): copied %d (%d)bytes of cached packet.\n",
+	    gci_p->BufferSize, gci_p->BufferLimit);
 #endif
 
 	/* 3. install isr */
@@ -235,22 +245,27 @@
 	PXE_IPADDR nic_ip;
 
 	nic_ip.ip = bootplayer.yip;	/* my ip */
-	printf("my ip: %d.%d.%d.%d\n", nic_ip.octet[0], nic_ip.octet[1], nic_ip.octet[2], nic_ip.octet[3]);
+	printf("my ip: %d.%d.%d.%d\n",
+	    nic_ip.octet[0], nic_ip.octet[1], nic_ip.octet[2], nic_ip.octet[3]);
 
 	/* my MAC */
 	pxe_memcpy(&bootplayer.CAddr, &nic_mac, MAC_ADDR_LEN);
-	printf("my MAC: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
-	    nic_mac[0], nic_mac[1], nic_mac[2], nic_mac[3], nic_mac[4], nic_mac[5]);
+	printf("my MAC: %6D\n", nic_mac, ":");
 
 	/* setting default ips*/
 	pxe_set_ip32(PXE_IP_MY, bootplayer.yip);	/* nic ip */
 	pxe_set_ip32(PXE_IP_SERVER, bootplayer.sip);	/* boot server ip */
 
-	pxe_set_ip32(PXE_IP_NAMESERVER, 0x0100a8c0);	/* nameserver ip, default to 192.168.0.1 */
-	pxe_set_ip32(PXE_IP_GATEWAY, 0x0100a8c0);	/* gateway ip, default to 192.168.0.1 */
-	pxe_set_ip32(PXE_IP_NETMASK, 0x00ffffff);	/* gateway ip, default to 255.255.255.0 */
-	pxe_set_ip32(PXE_IP_BROADCAST, 0xffffffff);	/* broadcast address, default to 255.255.255.255 */
-	pxe_set_ip32(PXE_IP_WWW, 0x0100a8c0);		/* web server */
+	/* nameserver ip, default to 192.168.0.1 */
+	pxe_set_ip32(PXE_IP_NAMESERVER, 0x0100a8c0);
+	/* gateway ip, default to 192.168.0.1 */
+	pxe_set_ip32(PXE_IP_GATEWAY, 0x0100a8c0);
+	/* netmask, default to 255.255.255.0 */
+	pxe_set_ip32(PXE_IP_NETMASK, 0x00ffffff);
+	/* broadcast address, default to 255.255.255.255 */
+	pxe_set_ip32(PXE_IP_BROADCAST, 0xffffffff);
+	/* web server */
+	pxe_set_ip32(PXE_IP_WWW, 0x0100a8c0);
 	
 	/* initing modules */	
 	pxe_arp_init();
@@ -289,22 +304,24 @@
 	pxe_memset(undi_info, 0, sizeof(t_PXENV_UNDI_GET_INFORMATION));
 
 	if (!pxe_core_call(PXENV_UNDI_GET_INFORMATION)) {
+		printf("pxe_core_install_isr(): failed get NIC information.\n");

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list