PERFORCE change 121429 for review

Alexey Tarasov taleks at FreeBSD.org
Mon Jun 11 12:19:58 UTC 2007


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

Change 121429 by taleks at taleks_th on 2007/06/11 12:19:29

	Aded pxe_await module hide receiving cycle from user code, updated other modules to use await functions.
	Updated DHCP client, now it is able to get earlier missed information about subnet/nameserver/gateway. Updated pxe_core to use  this facility, also added pxe_get_ip32() function instead of set of functions with similar names.
	DNS module now checks if provided string is striing value of ip address.
	Commented all used functions parameters more detailed.

Affected files ...

.. //depot/projects/soc2007/taleks-pxe_http/Makefile#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.h#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#14 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#12 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#4 edit

Differences ...

==== //depot/projects/soc2007/taleks-pxe_http/Makefile#6 (text+ko) ====

@@ -3,7 +3,7 @@
 LIB=		pxe_http
 INTERNALLIB=
 
-SRCS= pxe_conv.c pxe_isr.S pxe_mem.c pxe_buffer.c pxe_sock.c pxe_arp.c pxe_ip.c pxe_mutex.c \
+SRCS= pxe_conv.c pxe_isr.S pxe_mem.c pxe_buffer.c pxe_sock.c pxe_await.c pxe_arp.c pxe_ip.c pxe_mutex.c \
 	pxe_core.c pxe_icmp.c pxe_udp.c pxe_filter.c pxe_dns.c pxe_dhcp.c
 
 CFLAGS+=	-I${.CURDIR}/../../common -I${.CURDIR}/../btx/lib \
@@ -13,7 +13,7 @@
 CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand/
 
 #debug flag
-CFLAGS+=	-DPXE_DEBUG
+#CFLAGS+=	-DPXE_DEBUG
 #CFLAGS+=	-DPXE_DEBUG_HELL
 
 .include <bsd.lib.mk>

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

@@ -1,6 +1,7 @@
 #include <stand.h>
 
 #include "pxe_arp.h"
+#include "pxe_await.h"
 #include "pxe_conv.h"
 #include "pxe_core.h"
 #include "pxe_mem.h"
@@ -41,12 +42,12 @@
 
 	/* filling source related data: client ip & MAC */	
 	pxe_memcpy(pxe_get_mymac(), packet_to_send.body.src_hwaddr, 6);	
-	packet_to_send.body.src_paddr = pxe_get_myip32();
+	packet_to_send.body.src_paddr = pxe_get_ip32(PXE_IP_MY);
 	
 	/* filling entry for own ip/mac*/	
 	pxe_memcpy(pxe_get_mymac(), arp_table[MAX_ARP_ENTRIES].mac, 6);	
-	arp_table[MAX_ARP_ENTRIES].ip4.ip  = pxe_get_myip32();
-    
+	arp_table[MAX_ARP_ENTRIES].ip4.ip  = pxe_get_ip32(PXE_IP_MY);
+	
 	/* setting broadcast target address */
 	pxe_memset(packet_to_send.body.target_hwaddr, 0xff, 6); 
 }
@@ -73,6 +74,10 @@
 	return (NULL);
 }
 
+/* pxe_arp_stats() - show arp current table state
+ * in/out:
+ *	none
+ */
 void
 pxe_arp_stats()
 {
@@ -212,9 +217,10 @@
  *  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
+ *	ip	- target ip, for which to find MAC
  *  out:
- *	none   
+ *	0	- failed
+ *	1	- success
  */
 int
 pxe_arp_send_whois(uint32_t ip)
@@ -241,8 +247,54 @@
 	return (1);
 }
 
+/* pxe_arp_await() - await function for ARP replies
+ * in:
+ *	function	- await function
+ *	try_number	- number of try
+ *	timeout		- timeout from start of try
+ *	data		- pointer to PXE_ARP_WAIT_DATA
+ * out:
+ *	PXE_AWAIT_ constants
+ */
+int
+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 */
+		        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 
+								 */
+		if (res != NULL) {
+			wait_data->mac = res;
+			return (PXE_AWAIT_COMPLETED);
+		}
+		
+		return (PXE_AWAIT_CONTINUE);
+		break;		
 
+	case PXE_AWAIT_FINISHTRY:			/* don't handle finish of try */
+		printf("\npxe_arp_await(): ARP reply timeout.\n");
+		break;	
 
+	case PXE_AWAIT_END:				/* wait ended */
+	default:
+		break;
+	}
+	
+	return (PXE_AWAIT_OK);
+}
+
 /*
  *  pxe_arp_ip4mac() - returns MAC for given ip if it's found in arp_table,
  *                     otherwise - performs request sending
@@ -255,54 +307,19 @@
 const MAC_ADDR *
 pxe_arp_ip4mac(uint32_t ip) 
 {
-	int	timeToDie = PXE_TIME_TO_DIE;
-	int	trysLeft = PXE_MAX_ARP_TRY;
 
 	const MAC_ADDR *res = pxe_arp_table_search(ip);
 
 	if (res != NULL)
 		return (res);
 
-	if (pxe_arp_send_whois(ip) != 1) {
-		return NULL;
+	PXE_ARP_WAIT_DATA	wait_data;
+	
+	wait_data.ip = ip;
+	wait_data.mac = NULL;
+	
+	if (!pxe_await(pxe_arp_await, PXE_MAX_ARP_TRY, PXE_TIME_TO_DIE, &wait_data)) {
 	}
 
-	while (1) {
-#ifdef PXE_DEBUG			
-		twiddle();
-#endif
-		if (pxe_core_recv_packets()) {        	/* means some packet was received */
-			
-			res = pxe_arp_table_search(ip);	/* check if ARP protocol was called and 
-							 * arp_table updated */
-
-			if (res != NULL) {
-				return (res);
-			}
-
-		};
-
-		if (timeToDie == 0) {	
-
-			--trysLeft;
-			if (trysLeft == 0) { 	/* have not recieved anything, return nothing */
-
-				printf("\npxe_arp_ip4mac(): ARP reply timeout.\n");
-				return (NULL);
-			}
-
-			timeToDie = PXE_TIME_TO_DIE;
-
-			if (pxe_arp_send_whois(ip) != 1) {
-			    return (0);
-			}
-		}
-
-		/* sleep(1); */
-		delay(1000000);
-		--timeToDie;
-	}
-
-	/* never getting here*/
-	return (NULL);
+	return (wait_data.mac);
 }

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

@@ -18,10 +18,10 @@
 #define MAX_ARP_ENTRIES	4
 /* max try count to send/recieve ARP request/reply */
 #define PXE_MAX_ARP_TRY	3
-/* max timeout in seconds */
-#define PXE_TIME_TO_DIE 10
+/* max timeout in millyseconds */
+#define PXE_TIME_TO_DIE 15000
 
-/* define to anable caching incoming packet sender information*/
+/* define to enable caching incoming ARP packet sender information */
 #define PXE_ARP_SNIFF
 
 typedef struct pxe_arp_entry {
@@ -32,10 +32,13 @@
 
 /* initialisation routine */
 void pxe_arp_init();
+
 /* find MAC by provided ip */
 const MAC_ADDR *pxe_arp_ip4mac(uint32_t ip);
+
 /* protocol handler for received packets */
 int pxe_arp_protocol(PXE_PACKET *pack, uint8_t function, void *data);
+
 /* ARP table statistics */
 void pxe_arp_stats();
 
@@ -69,4 +72,9 @@
 	PXE_ARP_PACKET_ETH4	body;
 } __packed PXE_ARP_PACK_DATA;
 
+typedef struct pxe_arp_wait_data {
+	uint32_t		ip;
+	const MAC_ADDR		*mac;
+} PXE_ARP_WAIT_DATA;
+
 #endif

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

@@ -1,7 +1,14 @@
 #include "pxe_buffer.h"
 #include "pxe_mem.h"
 
-/* two functions to work with PXE_BUFFER, in FIFO mode */
+/* pxe_buffer_write() - write data to buffer, if possible
+ * in:
+ *	buf	- pointer to buffer structure
+ *	from	- pointer to data to write
+ *	size	- size of data buffer
+ * out:
+ *	actual count of written bytes
+ */
 uint16_t
 pxe_buffer_write(PXE_BUFFER *buf, const void *from, uint16_t size)
 {
@@ -33,7 +40,14 @@
 	return (to_write);
 }
 
-
+/* pxe_buffer_read() - reades data from buffer, if possible
+ * in:
+ *	buf	- pointer to buffer structure
+ *	to	- pointer to data to read to
+ *	size	- size of data buffer
+ * out:
+ *	actual count of read bytes
+ */
 uint16_t
 pxe_buffer_read(PXE_BUFFER *buf, void *to, uint16_t size)
 {
@@ -83,6 +97,12 @@
 	return (to_read);
 }
 
+/* pxe_buffer_space() - returns free space in buffer
+ * in:
+ *	buffer - pointer to buffer structure
+ * out:
+ *	count in bytes of free space in buffer
+ */
 uint16_t
 pxe_buffer_space(PXE_BUFFER *buffer)
 {
@@ -90,11 +110,19 @@
 	return buffer->bufleft;
 }
 
+/* pxe_buffer_memalloc() - allocates memory for buffer
+ * in:
+ *	buffer	- pointer to buffer structure
+ *	size	- bytes to allocate
+ * out:
+ *	0	- failed
+ *	1	- success
+ */
 int
 pxe_buffer_memalloc(PXE_BUFFER *buffer, uint16_t size)
 {
 
-	if (buffer->data != NULL) { /*don't alloc nothing, if mem already allocated*/
+	if (buffer->data != NULL) { /* don't alloc nothing, if mem already allocated */
 		return (0);
 	}
 	
@@ -106,6 +134,12 @@
 	return (1);
 }
 
+/* pxe_buffer_memfree() - release memory used by buffer
+ * in:
+ *	buffer	- pointer to buffer structure
+ * out:
+ *	none
+ */
 void
 pxe_buffer_memfree(PXE_BUFFER *buffer)
 {

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

@@ -8,20 +8,24 @@
 
 	void        *data;      /* pointer to memory block, used for buffer*/
 
-	uint16_t    fstart;
-	uint16_t    fend;
+	uint16_t    fstart;	/* start of free space part in buffer */
+	uint16_t    fend;	/* end of free space part in buffer */
 	
 	uint16_t    bufsize;    /* size of memory block */
 	uint16_t    bufleft;    /* left buffer space */
 
 } PXE_BUFFER;
 
+/* allocates memory for buffer */
+int	 pxe_buffer_memalloc(PXE_BUFFER *buffer, uint16_t size);
 
-int	 pxe_buffer_memalloc(PXE_BUFFER *buffer, uint16_t size);
+/* releases buffer memory */
 void	 pxe_buffer_memfree(PXE_BUFFER *buffer);
+
+/* writes data to buffer */
 uint16_t pxe_buffer_write(PXE_BUFFER *buffer, const void* data, uint16_t size);
-uint16_t pxe_buffer_free(PXE_BUFFER *buffer, void* to, uint16_t size);
+
+/* returns free space size in buffer */
 uint16_t pxe_buffer_space(PXE_BUFFER *buffer);
 
-
 #endif // PXE_BUFFER_H_INCLUDED

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

@@ -7,6 +7,7 @@
 #include "pxe_arp.h"
 #include "pxe_conv.h"
 #include "pxe_core.h"
+#include "pxe_dhcp.h"
 #include "pxe_ip.h"
 #include "pxe_isr.h"
 #include "pxe_mem.h"
@@ -35,9 +36,9 @@
 PXE_MUTEX           core_mutex = {0, 0};   /* mutex used in packet allocation */
 
 /* NIC info */
-PXE_IPADDR          nic_ip = {0};
 MAC_ADDR	    nic_mac;	/* may be init it also by zero? */
-PXE_IPADDR          ns_ip = {0};/* nameserver addr */
+/* IP related info */
+PXE_IPADDR	    core_ips[PXE_IP_MAX];
 
 /* core packet statistics */
 uint32_t   	    packets_dropped = 0;
@@ -45,8 +46,9 @@
 uint32_t   	    packets_received = 0;
 
 
-/*
- * performs startup call during pxe_core_init()
+/* pxe_core_undi_startup() - performs UNDI startup call during pxe_core_init()
+ * in:
+ *	none
  * out:
  *	1 - success
  *	0 - failed
@@ -71,8 +73,9 @@
         return (status);
 }
 
-/*
- * performs UNDI initialization  call during pxe_core_init()
+/* pxe_core_undi_init() - performs UNDI initialization  call during pxe_core_init()
+ * in:
+ *	none
  * out:
  *	1 - success
  *	0 - failed
@@ -96,10 +99,17 @@
 	return (status);
 }
 
+/* pxe_core_init() - performs initialization of all PXE related code
+ * in:
+ *	pxenv_p	- pointer to PXENV+ structure
+ *	pxe_p	- pointer to !PXE
+ * out:
+ *	0	- failed
+ *	1	- success
+ */
 int
 pxe_core_init(pxenv_t *pxenv_p, pxe_t* pxe_p)
 {
-/*	int i = 1;    /* packet index during initialization loop */
 #ifdef PXE_DEBUG
 	printf("pxe_core_init(): started (pxenv_p = 0x%x, pxe_p = 0x%x).\n", pxenv_p, pxe_p);
 #endif
@@ -115,12 +125,11 @@
 
 	pxe_memset(core_packets, 0, sizeof(core_packets));
 	pxe_memset(core_protocol, 0, sizeof(core_protocol));
-	nic_ip.ip = 0;
+	pxe_memset(core_ips, 0, sizeof(core_ips));
 	
 	pxenv = pxenv_p;
 	pxe = pxe_p;
 
-
 	/* 1. determine PXE API entry point */
 	if(pxenv_p == NULL)
 		return (0);
@@ -153,7 +162,7 @@
 	}
 
 #ifdef PXE_DEBUG
-	printf("pxe_core_init(): pxenv checked.\n");
+	printf("pxe_core_init(): PXENV+ checked.\n");
 #endif
     
 	/*
@@ -179,6 +188,7 @@
 		}
 	}
 
+	/* show version and entry point */
 	printf("\nPXE v.%d.%d",
 	       (uint8_t) (pxenv_p->Version >> 8),
 	       (uint8_t) (pxenv_p->Version & 0xFF));
@@ -187,16 +197,16 @@
 	       pxe_p->EntryPointSP.segment,
 	       pxe_p->EntryPointSP.offset);
 
+	/* setting entry point in tramp code */
 	__pxe_entry_seg = pxe->EntryPointSP.segment;
 	__pxe_entry_off = pxe->EntryPointSP.offset;
 	
 	/* 2. getting cached info */
 	gci_p = (t_PXENV_GET_CACHED_INFO *) scratch_buffer;
 	pxe_memset(gci_p, 0, sizeof(*gci_p)); 
+	/* getting Boot Server Discovery reply */
+	gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
 
-/*	gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;*/
-/**/
-	gci_p->PacketType = PXENV_PACKET_TYPE_DHCP_ACK;
 	gci_p->BufferSize = sizeof(BOOTPLAYER);
 	gci_p->Buffer.segment = VTOPSEG(&bootplayer);
 	gci_p->Buffer.offset = VTOPOFF(&bootplayer);
@@ -211,9 +221,6 @@
 		return (0);
 	}
 
-/*	pxe_memcpy(PTOV((gci_p->Buffer.segment << 4) + gci_p->Buffer.offset),
-	      &bootplayer, gci_p->BufferSize);
-*/
 #ifdef PXE_DEBUG
 	printf("pxe_core_init(): copied %d bytes of cached packet. Limit = %d.\n", gci_p->BufferSize, gci_p->BufferLimit);
 #endif
@@ -229,34 +236,43 @@
 	undi_open->R_Mcast_Buf.MCastAddrCount = 0;
 	
 	if (!pxe_core_call(PXENV_UNDI_OPEN)) {
+		printf("pxe_core_init(): failed to open network connection.\n");
+		return (0);
     	}
 	
-	/* saving information about NIC */
+	/* showing information about NIC */
+	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]);
-						/* my MAC */
+
+	/* 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("gip ip: 0x%8x\n", bootplayer.gip);
+	/* 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 */
 	
-	ns_ip.ip = 0x0100a8c0;		/* TODO: to determiny nameserver ip*/
-	
+	/* initing modules */	
 	pxe_arp_init();
 	pxe_filter_init();
+	pxe_icmp_init();
 	pxe_socket_init();
-	pxe_icmp_init();
 	pxe_udp_init();
 	
-	
-	pxe_ip_route_init(0x0100a8c0);	/* NOTE: setting default route 192.168.0.1
-					 * need to determiny gateway by getting info drom DHCP packets,
-					 * but cached packets for some resons have no gip set. So,
-					 * after implementing of UDP, need to return to this point and
-					 * get info sending DHCP  requests.
-					 */
-		
+	/* trying to get gateway/nameserver info from DHCP server */
+	pxe_dhcp_query(bootplayer.ident);
+
+	/* initing route tables, using DHCP reply data */	
+	pxe_ip_route_init(pxe_get_ip32(PXE_IP_GATEWAY));
+
 #ifdef PXE_DEBUG
 	printf("pxe_core_init(): ended.\n");
 #endif	
@@ -264,6 +280,10 @@
 	return (1);
 }
 
+/* pxe_core_install_isr() - installs ISR for NIC
+ * in/out:
+ *	none
+ */
 void
 pxe_core_install_isr()
 {
@@ -322,12 +342,21 @@
 #endif
 }
 
-/*
- * calls __mem_copy() to copy data in real mode to data buffer
+/* pxe_core_copy() -  calls __mem_copy() to copy data in real mode to data buffer,
+ *	usefull if data is in addresses inaccessible from user space. TODO: Check, if really needed.
+ * in:
+ *	seg_from - segment of source buffer
+ *	off_from - offset of source buffer
+ *	seg_to	 - segment of destination buffer
+ *	off_to	 - offset of destination buffer
+ *	size	 - number of bytes to copy
+ * out:
+ *	none
  */
 void
 pxe_core_copy(uint16_t seg_from, uint16_t off_from, uint16_t seg_to, uint16_t off_to, uint16_t size)
 {
+
 	pxe_memset(&v86, 0, sizeof(v86));
 
 	v86.ctl  = V86_ADDR | V86_CALLF | V86_FLAGS;
@@ -339,6 +368,10 @@
 	v86.ctl  = V86_FLAGS;
 }
 
+/* pxe_core_remove_isr() - restores default handler for interrupt
+ * in/out:
+ *	none
+ */
 void
 pxe_core_remove_isr()
 {
@@ -351,6 +384,13 @@
 	v86.ctl  = V86_FLAGS;
 }
 
+/* pxe_core_shutdown() - shutdown all modules. TODO: add needed modules shutdown.
+ * in:
+ *	none
+ * out:
+ *	0 - failed
+ *	1 - success
+ */
 int
 pxe_core_shutdown()
 {
@@ -391,7 +431,6 @@
 int
 pxe_core_call(int func)
 {
-
 #ifdef PXE_DEBUG_HELL
 	printf("pxe_core_call(): func = 0x%x...", func);
 #endif
@@ -415,6 +454,13 @@
 	return (status == 0) ? 1 : 0;
 }
 
+/* pxe_core_transmit() - transmits packet to network
+ * in:
+ *	pack - packet definition structure.
+ * out:
+ *	0 - failed
+ *	1 - success
+ */
 int
 pxe_core_transmit(PXE_PACKET *pack)
 {
@@ -490,7 +536,9 @@
 	return (status);
 }
 
-/* flushes pending, aborted, wrong and etc packets */
+/* TODO: think about removing of this function
+ * flushes pending, aborted, wrong and etc packets 
+ */
 int
 pxe_core_flush_packets()
 {
@@ -512,47 +560,15 @@
 	return (1);
 }
 
-/*
- *  checks if interrupt handler was executed for our NIC
- *    (in case of shared IRQs)
- *  in:
- *	none
- *  out:
- *	0 - not our interrupt, return
- *	1 - our, must handle receiving
+/* pxe_core_get_packet() - checks, if there are any new pacjets in receive queue
+ * in:
+ *	func	- function to fill in FuncFlag of t_PXENV_UND_ISR structure
+ *	undi_isr- pointer to t_PXENV_UND_ISR, used to return data (sizes and etc)
+ * out:
+ *	0 - failed
+ *	1 - success
  */
 int
-pxe_core_is_our()
-{
-	/*
-	 * NOTE: best idea to do it in real mode interrupt handler,
-	 *       The PXE specs suggest fast interrupt handling,
-	 *	 starting handler thread and returning
-	 */
-	t_PXENV_UNDI_ISR *undi_isr =
-		(t_PXENV_UNDI_ISR *)scratch_buffer;
-
-	bzero(undi_isr, sizeof(*undi_isr));
-
-	undi_isr->FuncFlag = PXENV_UNDI_ISR_IN_START;
-	pxe_core_call(PXENV_UNDI_ISR);
-
-	if (undi_isr->Status != 0) {	/* pxe_core_call() failed */
-		/* pretend, failed cause not ours interrupt */
-		return (0);
-	}
-
-	if (undi_isr->FuncFlag == PXENV_UNDI_ISR_OUT_OURS)
-		return (1);
-
-	return (0);
-}
-
-/*
-	0 - failed
-	1 - success
-*/
-int
 pxe_core_get_packet(int func, t_PXENV_UNDI_ISR *undi_isr )
 {
 #ifdef PXE_DEBUG_HELL
@@ -605,7 +621,7 @@
 		if (undi_isr->FuncFlag == PXENV_UNDI_ISR_OUT_RECIEVE) {
 			/* that's what we are waiting for */
 #ifdef PXE_DEBUG_HELL
-			printf("get_packet(): got packet!.\n");
+			printf("get_packet(): got packet!\n");
 #endif					
 			break;
 		}
@@ -622,8 +638,8 @@
 	return (1);
 }
 
-/*
- * recieves all packets, if there is any waiting in receiving queue.
+/* pxe_core_recv_packets() - recieves all packets, if there is any waiting in receiving queue.
+ *	and gives it to protocol callback functions.
  * in:
  *    none
  * out:
@@ -680,7 +696,8 @@
 	}
 	
 #ifdef PXE_DEBUG
-	printf("recv_packets(): size = %d, proto = %d, frame_length = %d bytes.\n", buffer_size, protocol, frame_size);
+	printf("recv_packets(): size = %d, proto = %d, frame_length = %d bytes.\n",
+	    buffer_size, protocol, frame_size);
 #endif		
 
 	/* we are interested in ARP & IP packets */
@@ -837,8 +854,14 @@
 	return (0);
 }
 
-/*
- * recieves in packet data
+/* pxe_core_recieve() - recieves sequentially fragments data in packet buffer
+ * in:
+ *	pack		- packet with buffer to receive in
+ *	frame_data	- fragment data buffer
+ *	frame_size	- frag,ent buffer size
+ * out:
+ *	0 - failed
+ *	1 - success
  */
 int
 pxe_core_recieve(PXE_PACKET *pack, void *frame_data, size_t frame_size)
@@ -857,7 +880,7 @@
 	return (1);
 }
 
-/*
+/* TODO: think if this function is needed
  * allocates packet, creates buffer for data if necessary
  */
 PXE_PACKET *
@@ -877,11 +900,6 @@
 			if (core_packets[i].data_size < packet_size) {
 				/* packet contains less memmory than needed */
 
-/*				void *data = pxe_alloc(packet_size);
-				pxe_free(core_packets[i].data);
-				core_packets[i].data = data;
-*/
-
 				void *data = pxe_alloc(packet_size + MEDIAHDR_LEN_ETH);
 				pxe_free(core_packets[i].data);
 				core_packets[i].raw_data = data;
@@ -912,7 +930,7 @@
 	return (NULL);
 }
 
-/*
+/* TODO: think if this function is useful
  * commits choosed packet, free used structures
  */
 void
@@ -924,7 +942,7 @@
 	pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
 }
 
-/*
+/* TODO: think if this function is useful
  * drops choosed packet
  */
 void
@@ -935,8 +953,12 @@
 	pxe_core_commit(pack);
 }
 
-/*
- *   registers protocol in protocols table
+/* pxe_core_register() -  registers protocol in protocols table
+ * in:
+ * 	proto	- IP protocol number
+ *	proc	- callback
+ * out:
+ *	none
  */
 void
 pxe_core_register(uint8_t proto, pxe_protocol_call proc)
@@ -945,30 +967,44 @@
     core_protocol[proto]=proc;
 }
 
-uint32_t
-pxe_get_myip32()
+/* pxe_get_mymac() - returns NIC MAC
+ * in:
+ *	none
+ * out:
+ *	non NULL pointer to MAC_ADDR
+ */
+const MAC_ADDR*
+pxe_get_mymac()
 {
-
-	return nic_ip.ip;
+	return (const MAC_ADDR *)&nic_mac;
 }
 
+/* pxe_get_ip32() - returns ip related data, specified by id parameter
+ * in:
+ *	id - id of needed data (PXE_IP_ constants)
+ * out:
+ *	associated with this id value
+ */
 uint32_t
-pxe_get_nsip32()
+pxe_get_ip32(uint8_t id)
 {
-
-	return ns_ip.ip;
+	if (id < PXE_IP_MAX)
+	    return core_ips[id].ip;
+	    
+	return (0);
 }
 
+/* pxe_set_ip32() - sets ip related data, specified by id parameter
+ * in:
+ *	id	- id of needed data (PXE_IP_ constants)
+ *	new_ip	- new uint32_t data
+ * out:
+ *	none
+ */
 void
-pxe_set_nsip32(uint32_t new_ip)
+pxe_set_ip32(uint8_t id, uint32_t new_ip)
 {
-
-	ns_ip.ip = new_ip;
+	if (id < PXE_IP_MAX) {
+		core_ips[id].ip = new_ip;
+	}
 }
-
-const MAC_ADDR*
-pxe_get_mymac()
-{
-	return (const MAC_ADDR *)&nic_mac;
-}
-

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

@@ -5,9 +5,6 @@
 #include <stddef.h>
 
 #include "../libi386/pxe.h"
-/* PXE structures and function codes
-#include "sys/boot/libi386/pxe.h"
-*/
 
 /*
  *  contains wrappers for UNDI functions
@@ -32,9 +29,6 @@
  */
 typedef struct pxe_packet {
 
-/*  pxe_packet* next;       /* NOT IMPLEMENTED: two-linked list */
-/*  pxe_packet* prev;       /* NOT IMPLEMENTED: two-linked list */
-
     uint8_t     protocol;   /* protocol, used in packet */
     uint8_t     state;      /* state of  packet (PXE_PACKET_STATE_ ... ) */
     uint8_t	flags;      /* flags if it is broadcast packet */
@@ -105,20 +99,24 @@
 #define PXE_CORE_HANDLE    0x0
 #define PXE_CORE_CHECK     0x1
 #define PXE_CORE_FRAG      0x2
+/* protocol callback function type*/
 typedef int (*pxe_protocol_call)(PXE_PACKET *pack, uint8_t function, void *data);
 
 /* registers protocol */
 void pxe_core_register(uint8_t ip_proto, pxe_protocol_call proc);
 
-/* returns NIC ip */
-uint32_t pxe_get_myip32();
-
 /* returns NIC MAC */
 const MAC_ADDR *pxe_get_mymac();
 
-/* returns nameserver ip */
-uint32_t pxe_get_nsip32();
-/* sets nameserver ip */
-void	 pxe_set_nsip32(uint32_t new_ns);
+#define PXE_IP_MY		0
+#define PXE_IP_NET		1
+#define PXE_IP_NETMASK		2
+#define PXE_IP_NAMESERVER	3
+#define PXE_IP_GATEWAY		4
+#define PXE_IP_BROADCAST	5
+#define PXE_IP_SERVER		6
+#define PXE_IP_MAX		7
+uint32_t pxe_get_ip32(uint8_t id);
+void	 pxe_set_ip32(uint8_t id, uint32_t ip);
 
 #endif // PXE_CORE_H_INCLUDED

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

@@ -1,5 +1,6 @@
 #include <stand.h>
 
+#include "pxe_await.h"
 #include "pxe_conv.h"
 #include "pxe_core.h"
 #include "pxe_dhcp.h"
@@ -30,19 +31,26 @@
 	return (opt + sizeof(PXE_DHCP_OPT_HDR) + opt_len);
 }
 
+/* parses options section of packet
+ * in:
+ *	opts 		- pointer to options section
+ *	max_size 	- size of option section data
+ *	result		- pointer to result return structure
+ * out:
+ *	result		- result of parsing options
+ */
 void
-print_dhcp_options(uint8_t *opts)
+pxe_dhcp_parse_options(uint8_t *opts, uint16_t max_size, PXE_DHCP_PARSE_RESULT *result)
 {
         uint8_t *p=opts;
         uint8_t code = opts[0];
         uint8_t len = 0;
-			
+
         printf("DHCP options:\n");
 				
         while (code != PXE_DHCP_OPT_END) {
                 ++p;
                 len = 1 + (*p);
-                printf(".");
 
                 switch (code) {
 	                case 0: /* pad */
@@ -50,18 +58,63 @@
 	                        break;
 
 	                case PXE_DHCP_OPT_NETMASK:
-	                        printf("\nnetmask: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+	                        printf("netmask: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+				result->netmask = *((uint32_t *)(p+1));
 	                        break;
 
 	                case PXE_DHCP_OPT_ROUTER: 
-	                        printf("\nfirst router: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+	                        printf("first router: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+				result->gw = *((uint32_t *)(p+1));
 	                        break;
 
 	                case PXE_DHCP_OPT_NAMESERVER:
-	                        printf("\nfirst nameserver: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+	                        printf("first nameserver: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+				result->ns = *((uint32_t *)(p+1));
+	                        break;
+
+	                case PXE_DHCP_OPT_TYPE:
+				result->message_type = *(p+1);
+#ifdef PXE_DEBUG
+	                        printf("message type: 0x%x\n", result->message_type);
+#endif				
+	                        break;
+				
+	                case PXE_DHCP_OPT_LEASE_TIME:
+#ifdef PXE_DEBUG
+	                        printf("lease time: %d secs\n", le2be32( *((uint32_t *)(p+1)) ) );
+#endif				

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


More information about the p4-projects mailing list