PERFORCE change 119772 for review

Alexey Tarasov taleks at FreeBSD.org
Sun May 13 15:46:15 UTC 2007


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

Change 119772 by taleks at taleks_th on 2007/05/13 15:46:00

	Cosmetic changes, made all compilable together, added simple makefile.

Affected files ...

.. //depot/projects/soc2007/taleks-pxe_http/Makefile#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.S#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mutex.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mutex.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#3 edit

Differences ...

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

@@ -5,37 +5,54 @@
 #include "pxe_core.h"
 #include "pxe_mem.h"
 
-static pxe_arp_entry		arp_table[MAX_ARP_ENTRIES];
-static pxe_arp_pack_data	packet_to_send;	
+static PXE_ARP_ENTRY		arp_table[MAX_ARP_ENTRIES];
+static PXE_ARP_PACK_DATA	packet_to_send;	
 static int			arp_usage = 0;
 
+/*
+ *  pxe_arp_init() - initialisation of used by this module structures
+ *  in:
+ *	none
+ *  out:
+ *	none
+ */
 void
 pxe_arp_init()
 {
 
-	pxe_memset(&packet_to_send, 0, sizeof(pxe_arp_pack_data) );
+	pxe_memset(&packet_to_send, 0, sizeof(PXE_ARP_PACK_DATA) );
 	/* now body.target_hwaddr filled with zero, which means broadcast MAC */
 
 	pxe_memset(arp_table, 0, sizeof(arp_table));
 
 	/* filling packet_to_send, it will not change ever */	
-	packet_to_send.hdr.hwtype = le2be16(ETH_TYPE);
+	packet_to_send.hdr.hwtype = le2be16(ETHER_TYPE);
 	packet_to_send.hdr.ptype = le2be16(PXE_PTYPE_IP);
 	packet_to_send.hdr.hsize = 6;	/* Ethernet MAC size */
 	packet_to_send.hdr.psize = 4;	/* ip4 size */
 	packet_to_send.hdr.operation = PXE_ARPOP_REQUEST;
-	
+	/* 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 = le2be32(pxe_get_myip32());
 }
 
+/*
+ *  pxe_arp_protocol() - process received arp packet, this function is called in style
+ *                     of pxe_protocol_call function type, but last two parameters are unused
+ *  in:
+ *	pack     - rceived packet data
+ *	function - protocal function (will be always PXE_CORE_FRAG)
+ *	data     - always NULL
+ *  out:
+ *	always 0 - we are not interested in storing this packet in pxe_core queue
+ */
 int
-pxe_arp_protocol(pxe_packet *pack, uint8_t function, void *data)
+pxe_arp_protocol(PXE_PACKET *pack, uint8_t function, void *data)
 {
 
-	const pxe_arp_pack_data *arp_reply = (const pxe_arp_pack_data *)pack->data;
+	const PXE_ARP_PACK_DATA *arp_reply = (const PXE_ARP_PACK_DATA *)pack->data;
 
-	if (arp_reply.hdr.operation != PXE_ARPOP_REPLY)	/* we don't need answer for requests. May be. */
+	if (arp_reply->hdr.operation != PXE_ARPOP_REPLY) /* we don't need answer for requests. May be. */
 		return 0;
 
 	/* if arp_usage exceeds MAX_ARP_ENTRIES, occurs rewriting of earlier placed ARP entries.
@@ -44,19 +61,27 @@
 	 * 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.
 	 */	
-	pxe_memcpy(&arp_reply.body.src_hwaddr, &arp_table[arp_usage % MAX_ARP_ENTRIES].mac, 6);
-	arp_table[arp_usage % MAX_ARP_ENTRIES].ip4 = arp_reply.body.
+	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 = be2le32(arp_reply->body.src_paddr);
 	++arp_usage;
 	
 	return 0; /* inform pxe_get_packet() we don't need this packet more. */
 }
 
+/*
+ *  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:
+ *	none   
+ */
 void
 pxe_arp_send_whois(uint32_t ip)
 {
-        pxe_packet	pack;
+        PXE_PACKET	pack;
 	
-	pack.data_size = sizeof(pxe_arp_pack_data);
+	pack.data_size = sizeof(PXE_ARP_PACK_DATA);
 	pack.data = &packet_to_send;
 
 	packet_to_send.body.target_paddr = le2be32(ip);
@@ -66,19 +91,37 @@
 	}
 }
 
+/*
+ *  pxe_arp_table_search() - searches entry in ARP table for given ip
+ *  in:
+ *	ip     - ip, for which to search MAC
+ *  out:
+ *	NULL   - not found such entry in arp_table
+ *	not NULL - pointer to MAC address
+ */
 const MAC_ADDR *
 pxe_arp_table_search(uint32_t ip)
 {
+	int entry = 0;
+	
+	for (; entry < MAX_ARP_ENTRIES; ++entry) {
 
-	for (int entry = 0; entry < MAX_ARP_ENTRIES; ++entry) {
-
 		if (arp_table[entry].ip4.ip == ip)
-			return &arp_table[entry];
+			return &arp_table[entry].mac;
 	}
 
 	return NULL;
 }
 
+/*
+ *  pxe_arp_ip4mac() - returns MAC for given ip if it's found in arp_table,
+ *                     otherwise - performs request sending
+ *  in:
+ *	ip     - ip, for which to search MAC
+ *  out:
+ *	NULL   - not found such entry in arp_table
+ *	not NULL - pointer to MAC address
+ */
 const MAC_ADDR *
 pxe_arp_ip4mac(uint32_t ip) 
 {
@@ -88,7 +131,7 @@
 	const MAC_ADDR *res = pxe_arp_table_search(ip);
 
 	if (res != NULL)
-		return res;
+		return (res);
 
 	pxe_arp_send_whois(ip);
 
@@ -100,7 +143,7 @@
 							 * arp_table updated */
 
 			if (res != NULL) {
-				return res;
+				return (res);
 			}
 
 		};
@@ -111,7 +154,7 @@
 			printf(".");
 #endif 
 			--trysLeft;
-			if (0 == trysLeft) { 	/* have not recieved anything, return nothing */
+			if (trysLeft == 0) { 	/* have not recieved anything, return nothing */
 
 				printf("ARP sending timeout.\n");
 				return (NULL);
@@ -124,4 +167,7 @@
 		sleep(1);
 		--timeToDie;
 	}
-}+
+	/* never getting here*/
+	return (NULL);
+}

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

@@ -12,49 +12,53 @@
 #include "pxe_core.h"
 #include "pxe_ip.h"
 
+/* max MAC<->ip4 bindings to store */
 #define MAX_ARP_ENTRIES	4
+/* max try count to send/recieve ARP request/reply */
+#define PXE_MAX_ARP_TRY	5
+/* max timeout in seconds */
+#define PXE_TIME_TO_DIE 60
 
 typedef struct pxe_arp_entry {
-	pxe_ipaddr	ip4;
+	PXE_IPADDR	ip4;
 	MAC_ADDR	mac;
 } PXE_ARP_ENTRY;
 
 
-/* NULL if cannot find such entry in ARP table */
+/* initialisation routine */
+void pxe_arp_init();
+/* find MAC by provided ip */
 const MAC_ADDR* pxe_arp_ip4mac(uint32_t ip);
-int pxe_arp_protocol(pxe_packet *pack, uint8_t function, void *data);
+/* protocol handler for received packets */
+int pxe_arp_protocol(PXE_PACKET *pack, uint8_t function, void *data);
 
+/* ARP packet types */
 #define PXE_ARPOP_REQUEST	1
 #define PXE_ARPOP_REPLY		2
 
+/* protocol types */
 #define PXE_PTYPE_IP	0x0800		/* IP4 protocol, used in ARP request */
 
 
 /* NOTE: here will be realised ARP for Ethernet and IP4 */
-struct pxe_arp_packet {
-	uint16_t hwtype;		/* hardware type */
+typedef struct pxe_arp_packet {
+	uint16_t hwtype;	/* hardware type */
 	uint16_t ptype;		/* protocol type */
 	uint8_t  hsize;		/* size of hardware address */
 	uint8_t  psize;		/* size of protocol adress */
 	uint16_t operation;
-} PXE_ARP_PACKET;
+} __packed PXE_ARP_PACKET;
 
-struct pxe_arp_packet_eth4 {
+typedef struct pxe_arp_packet_eth4 {
 	uint8_t  src_hwaddr[6];		/* source hardware address */
-	uint8_t  src_paddr[4];		/* source protocol address */
+	uint32_t src_paddr;		/* source protocol address */
 	uint8_t  target_hwaddr[6];	/* target hardware address if known */
-	uint8_t  target_paddr[4];	/* target protocol address if known */
-} PXE_ARP_PACKET_ETH4
+	uint32_t target_paddr;		/* target protocol address if known */
+} __packed PXE_ARP_PACKET_ETH4;
 
-struct pxe_arp_pack_data {
-        pxe_arp_packet		hdr;
-	pxe_arp_packet_eth4     body;
-} PXE_ARP_PACK_DATA
+typedef struct pxe_arp_pack_data {
+        PXE_ARP_PACKET	hdr;
+	PXE_ARP_PACKET_ETH4	body;
+} __packed PXE_ARP_PACK_DATA;
 
-/* max try count to send/recieve ARP request/reply */
-#define PXE_MAX_ARP_TRY	5
-/* max timeout in seconds */
-#define PXE_TIME_TO_DIE 60
-
-void pxe_arp_init();
-#endif+#endif

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

@@ -18,8 +18,8 @@
 /* NOTE: to think about using of this buffers */
 #define	PXE_BUFFER_SIZE		0x2000
 #define	PXE_TFTP_BUFFER_SIZE	512
-static char         scratch_buffer[PXE_BUFFER_SIZE];
-static char         data_buffer[PXE_BUFFER_SIZE];
+static uint8_t      scratch_buffer[PXE_BUFFER_SIZE];
+static uint8_t      data_buffer[PXE_BUFFER_SIZE];
 static pxenv_t	    *pxenv_p = NULL;    /* PXENV+ */
 static pxe_t	    *pxe_p   = NULL;    /* !PXE */
 static BOOTPLAYER   bootplayer;         /* PXE Cached information. */
@@ -33,12 +33,12 @@
 extern void         __pxenventry(void);
 
 /* pxe core structures*/
-pxe_packet          core_packets[PXE_MAX_PACKETS];  /* buffered packets */
+PXE_PACKET          core_packets[PXE_MAX_PACKETS];  /* buffered packets */
 pxe_protocol_call   core_protocol[256];    /* protocol's  callback fuctions */
-pxe_mutex           core_mutex = {0, 0};   /* mutex used in packet allocation */
+PXE_MUTEX           core_mutex = {0, 0};   /* mutex used in packet allocation */
 
 /* NIC info */
-pxe_ipaddr          nic_ip = {0};
+PXE_IPADDR          nic_ip = {0};
 MAC_ADDR	    nic_mac;	/* may be init it also by zero? */
 
 /* core packet statistics */
@@ -170,9 +170,9 @@
 	/* 3. additional start UNDI */
 
 	/* saving information about NIC */
-	nic_ip.ip=bootplayer.yip;	/* my ip */
+	nic_ip.ip = be2le32(bootplayer.yip);	/* my ip */
 					/* my MAC */
-	pxe_memcpy(&nic_mac, bootplayer.CAddr, MAC_ADDR_LEN);
+	pxe_memcpy(&nic_mac, &bootplayer.CAddr, MAC_ADDR_LEN);
 
 	return (1);
 }
@@ -217,7 +217,6 @@
 
 	v86.ctl  = V86_ADDR | V86_CALLF | V86_FLAGS;
 	v86.addr = (VTOPSEG(__isr_install) << 16) | VTOPOFF(__isr_install);
-	v86.ebx  = func;
 	v86int();
 	v86.ctl  = V86_FLAGS;
 #else
@@ -251,8 +250,7 @@
 	bzero(&v86, sizeof(v86));
 
 	v86.ctl  = V86_ADDR | V86_CALLF | V86_FLAGS;
-	v86.addr = (VTOPSEG(__isr_uninstall) << 16) | VTOPOFF(__isr_uninstall);
-	v86.ebx  = func;
+	v86.addr = (VTOPSEG(__isr_remove) << 16) | VTOPOFF(__isr_remove);
 	v86int();
 	v86.ctl  = V86_FLAGS;
 
@@ -313,15 +311,15 @@
 }
 
 int
-pxe_core_transmit(pxe_packet *pack)
+pxe_core_transmit(PXE_PACKET *pack)
 {
-	/* NOTE:all provided data must be in base segment of PXE,
+	/* NOTE:all provided data must be in base memory,
 	 *   if it's not here, it must be copied here (TO IMPLEMENT)
 	 */
 	t_PXENV_UNDI_TRANSMIT *undi_send =
 		(t_PXENV_UNDI_TRANSMIT *)scratch_buffer;
 
-	bzero(undi_send, sizeof(*undi_info));
+	bzero(undi_send, sizeof(*undi_send));
 
 	t_PXENV_UNDI_TBD	tbd;
 	tbd.ImmedLength = pack->data_size;	/* packet length */
@@ -332,7 +330,7 @@
 	undi_send->Protocol = pack->protocol;
 	undi_send->DestAddr.segment = VTOPSEG(pack->dest_mac);
 	undi_send->DestAddr.offset  = VTOPOFF(pack->dest_mac);
-	undi_send->TBD.segment = VTOPSEG(&tbd);	/* SEGOFF16 to xmit block data*/
+	undi_send->TBD.segment = VTOPSEG(&tbd);	/* SEGOFF16 to xmit block data */
 	undi_send->TBD.offset = VTOPOFF(&tbd);
 
 /* NOTE: is it needed? we use only immediate block */
@@ -340,15 +338,15 @@
 /*	we've inited undi_info with zero, so two lines below are not needed */
 /*	tbd.DataBlk[0].TDRsvdByte = 0;		/* reserved */
 /*	tbd.DataBlk[1].TDRsvdByte = 0;		/* reserved */
-	tbd.DataBlk[0].TDDataLen=tbd.ImmedLength; /* size of packet*/
-	tbd.DataBlk[0].TDPtrType = 1;		/* segment:offset type */
-	tbd.DataBlk[0].TDDataPtr.segment = VTOPSEG(pack->data);;
-	tbd.DataBlk[0].TDDataPtr.offset = VTOPOFF(pack->data);;
+	tbd.DataBlock[0].TDDataLen=tbd.ImmedLength; /* size of packet*/
+	tbd.DataBlock[0].TDPtrType = 1;		/* segment:offset type */
+	tbd.DataBlock[0].TDDataPtr.segment = VTOPSEG(pack->data);;
+	tbd.DataBlock[0].TDDataPtr.offset = VTOPOFF(pack->data);;
 
-	pxe_core_call(PXENV_UNDI_TRANSMIT_PACKET);
+	pxe_core_call(PXENV_UNDI_TRANSMIT);
 
 	if (undi_send->Status != 0) {
-		printf("pxe_core_transmit(): failed %x\n", undi_info->Status);
+		printf("pxe_core_transmit(): failed %x\n", undi_send->Status);
 		return (0);
 	}
 
@@ -362,7 +360,7 @@
 	int i = 0;
 
 	for (; i < PXE_MAX_PACKETS; ++i) {
-		pxe_ip *iphdr=(pxe_ip *)(core_packets[i].data);
+		PXE_IP_HDR *iphdr=(PXE_IP_HDR *)(core_packets[i].data);
 
 		if (iphdr == NULL) {   /* dummy packet */
 			continue;
@@ -399,7 +397,7 @@
 
 	bzero(undi_isr, sizeof(*undi_isr));
 
-	undi_isr->FuncFlag=PXENV_UNDI_ISR_IN_START;
+	undi_isr->FuncFlag = PXENV_UNDI_ISR_IN_START;
 	pxe_core_call(PXENV_UNDI_ISR);
 
 	if (undi_isr->Status != 0) {	/* pxe_core_call() failed */
@@ -470,7 +468,7 @@
 }
 
 /*
- * recieves one packet, if there is any waiting in receiving queue.
+ * recieves all packets, if there is any waiting in receiving queue.
  * in:
  *    none
  * out:
@@ -493,14 +491,14 @@
 	int	drop_flag = 0;
 	int	processed_packets = 0;
 
-	pxe_packet *pack=NULL;	/* allocated packet */
-	pxe_packet dummy_pack;	/* temporary struct, used to mimic
+	PXE_PACKET *pack=NULL;	/* allocated packet */
+	PXE_PACKET  dummy_pack;	/* temporary struct, used to mimic
 				 * real packet struct
 				 */
 	if (__pxe_isr_occured == 0) /* there are no packets for us to handle */
 		return (0);
 
-	__pxe_isr_occured = 0;
+	__pxe_isr_occured = 0; /* reset flag */
 
 	t_PXENV_UNDI_ISR *undi_isr =
 		(t_PXENV_UNDI_ISR *)scratch_buffer;
@@ -508,7 +506,7 @@
 	bzero(undi_isr, sizeof(*undi_isr));
 
 	/* starting packet receive cycle */
-	/* NOTE: pxe_core_recv_packet() name is similar tp pxe_core_get_packet(),
+	/* NOTE: pxe_core_recv_packets() name is similar tp pxe_core_get_packet(),
 	 *       may be renaming is needed.
 	 */
 	int func = PXENV_UNDI_ISR_IN_PROCESS;
@@ -542,7 +540,7 @@
 
 	if (!drop_flag) {
 
-		pxe_ip *iphdr = (pxe_ip *)frame_data;
+		PXE_IP_HDR *iphdr = (PXE_IP_HDR *)frame_data;
 
 		dummy_pack.protocol = protocol;
 		dummy_pack.state = PXE_PACKET_STATE_USING;
@@ -555,9 +553,9 @@
 			pxe_arp_protocol(&dummy_pack, PXE_CORE_FRAG, NULL);
 			++processed_packets;
 
-			/* aasume ARP packet always in opne fragment */
+			/* aasume ARP packet always in one fragment */
 		
-			func = PXE_UNDI_ISR_IN_GET_NEXT;
+			func = PXENV_UNDI_ISR_IN_GET_NEXT;
 
 			goto packet_start;
 		}
@@ -579,7 +577,10 @@
 				/* trying to get free packets by sending and dropping */
 				pack = pxe_core_alloc_packet(buffer_size);
 
-				/* failed to alloc packet, dropping packet */
+				/* failed to alloc packet, dropping packet
+				 * NOTE: may be good idea, simply abort current receive cycle,
+				 *       and wait if some protocol will free packet 
+				 */
 				if (pack == NULL) {
 					++packets_dropped;
 					drop_flag = 1;
@@ -598,7 +599,7 @@
 
 	while (received < buffer_size) {
 
-		if (!pxe_core_get_packet(PXENV_UNDI_ISR_GET_NEXT, undi_isr))
+		if (!pxe_core_get_packet(PXENV_UNDI_ISR_IN_GET_NEXT, undi_isr))
 			break;
 
 		frame_size = undi_isr->FrameLength;
@@ -625,7 +626,7 @@
 		pack->user_data = NULL;
 		++packets_received;
 
-		pxe_ip *iphdr=(pxe_ip *)pack->data;
+		PXE_IP_HDR *iphdr=(PXE_IP_HDR *)pack->data;
 
 		/* TODO: calc ip checksum */
 		pack->protocol = protocol;
@@ -640,19 +641,19 @@
 	++processed_packets;
 	/* received one or more packets, but need check if there are any others */
 	
-	func = PXE_UNDI_ISR_IN_GET_NEXT;
+	func = PXENV_UNDI_ISR_IN_GET_NEXT;
 
 	goto packet_start;
 
 	/* never getting here */
-	return (0);	
+	return (0);
 }
 
 /*
  * recieves in packet data
  */
 int
-pxe_core_recieve(pxe_packet *pack, void *frame_data, size_t frame_size)
+pxe_core_recieve(PXE_PACKET *pack, void *frame_data, size_t frame_size)
 {
 
 	/* check to be sure */
@@ -671,7 +672,7 @@
 /*
  * allocates packet, creates buffer for data if necessary
  */
-pxe_packet *
+PXE_PACKET *
 pxe_core_alloc_packet(size_t packet_size)
 {
 	int i = 1;    /* packet index */
@@ -694,6 +695,7 @@
 				/* failed to allocate enough memory for packet */
 				if (data == NULL) {
 					core_packets[i].data_size = 0;
+					pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
 					return (NULL);
 				}
 
@@ -713,7 +715,7 @@
  * drops choosed packet
  */
 void
-pxe_core_drop(pxe_packet *pack)
+pxe_core_drop(PXE_PACKET *pack)
 {
 
 	pxe_mutex_own(&core_mutex, PXE_OWNER_CORE);
@@ -742,6 +744,6 @@
 const MAC_ADDR*
 pxe_get_mymac()
 {
-	return &nic_mac;
+	return (const MAC_ADDR *)&nic_mac;
 }
 

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

@@ -4,6 +4,7 @@
 #include <stdint.h>
 #include <stddef.h>
 
+#include "pxe.h"
 /* PXE structures and function codes
 #include "sys/boot/libi386/pxe.h"
 */
@@ -32,7 +33,7 @@
 
     uint8_t     protocol;   /* protocol, used in packet */
     uint8_t     state;      /* state of  packet (PXE_PACKET_STATE_ ... ) */
-
+    
     void*       data;       /* pointer to buffer with packet data */
     size_t      data_size;  /* size of packet data */
                             
@@ -56,17 +57,18 @@
 int pxe_core_shutdown();
 
 /* sends packet to a network */
-int pxe_core_transmit(pxe_packet *pack);
+int pxe_core_transmit(PXE_PACKET *pack);
 
 /* commits that packet will not be used */
-void pxe_core_commit(pxe_packet *pack);
+void pxe_core_commit(PXE_PACKET *pack);
 
 /* allocates buffer for packet */
-pxe_packet *pxe_core_alloc_packet(size_t packet_size);
+PXE_PACKET *pxe_core_alloc_packet(size_t packet_size);
 
 /* interrupt handler function, that used to get new packets */
 void pxe_core_isr();
-/* recieves one packet if it's waiting */
+
+/* recieves all packets if it's waiting in queue, and calls protocols if needed */
 int pxe_core_recv_packets();
 
 /* calls PXE/UNDI API, registers of processor must be filled in with
@@ -81,10 +83,10 @@
 void pxe_core_remove_isr();
 
 /* stores data in packet */
-int pxe_core_recieve(pxe_packet *pack, void *data, size_t size);
+int pxe_core_recieve(PXE_PACKET *pack, void *data, size_t size);
 
 /* drops allocated packet, updates drop count */
-void pxe_core_drop(pxe_packet *pack);
+void pxe_core_drop(PXE_PACKET *pack);
 
 /* debug function that shows different information about usage */
 void pxe_core_stats();
@@ -92,13 +94,14 @@
 #define PXE_CORE_HANDLE    0x0
 #define PXE_CORE_CHECK     0x1
 #define PXE_CORE_FRAG      0x2
-typedef int (*pxe_protocol_call)(pxe_packet *pack, uint8_t function, void *data);
+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();
 

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

@@ -10,7 +10,7 @@
 static pinging = 0;
 
 int
-pxe_icmp_callback(pxe_packet *pack, uint8_t function, void *data)
+pxe_icmp_callback(PXE_PACKET *pack, uint8_t function, void *data)
 {
 
  	/* we don't store icmp packets, so they cannot steal memory
@@ -27,18 +27,18 @@
 	 */
 
 	/* icmp header*/
-	pxe_ip	*iphdr = pack->data;
+	PXE_IP_HDR	*iphdr = (PXE_IP_HDR *)pack->data;
 	size_t	iphdr_len = (iphdr->ver_ihl & 0x0f) * 4;
-	size_t	data_size = iphdr->length - iphdr_len - sizeof(pxe_ip);
-	pxe_icmp *icmphdr = pack->data + sizeof(pxe_ip) + iphdr_len;
+	size_t	data_size = iphdr->length - iphdr_len - sizeof(PXE_IP_HDR);
+	PXE_ICMP_HDR *icmphdr = (PXE_ICMP_HDR *)(pack->data + sizeof(PXE_IP_HDR) + iphdr_len);
 
 	/* TODO: verify checksum */
 
 	/* reply */
-	pxe_packet *pack_out = NULL;
-	pxe_ip	   *reply_iphdr = NULL;
-	pxe_icmp   *reply_icmphdr = NULL;
-	size_t     reply_size = sizeof(pxe_ip) + sizeof(pxe_icmp) + data_size;
+	PXE_PACKET *pack_out = NULL;
+	PXE_IP_HDR *reply_iphdr = NULL;
+	PXE_ICMP_HDR  *reply_icmphdr = NULL;
+	size_t     reply_size = sizeof(PXE_IP_HDR) + sizeof(PXE_ICMP_HDR) + data_size;
 
 	/* we are interested only in echo related packets*/
 	switch(icmphdr->code) {
@@ -63,35 +63,35 @@
 	}
 	/* all we need now is echo reply */
 
-	pxe_packet* pack_out = pxe_core_alloc_packet(reply_size);
+	pack_out = pxe_core_alloc_packet(reply_size);
 
-	if (pack == NULL) {
+	if (pack_out == NULL) {
 		/* TO THINK: failed to allocate packet,
 		 * may be it's better to use
 		 * statically allocated packet.
 		 */
-		return 0;
+		return (0);
 	}
 
-	reply_iphdr = (pxe_ip *)pack_out->data;
-	reply_icmphdr = (pxe_icmp *)(reply_iphdr + 1);
+	reply_iphdr = (PXE_IP_HDR *)pack_out->data;
+	reply_icmphdr = (PXE_ICMP_HDR *)(reply_iphdr + 1);
 
 	reply_icmphdr->type = PXE_ICMP_ECHO_REPLY;
 
 	/* copying same values */
 	reply_icmphdr->code = icmphdr->code;
 	reply_icmphdr->seq_num = icmphdr->seq_num;
-	reply_icmphdr->packet_id = icmphdr->reply_icmphdr;
+	reply_icmphdr->packet_id = icmphdr->packet_id;
 	reply_icmphdr->checksum = 0;
 	reply_icmphdr->checksum =
-	    ~(le2be16(pxe_ip_checksum(reply_icmphdr, sizeof(pxe_icmp))));
+	    ~(le2be16(pxe_ip_checksum(reply_icmphdr, sizeof(PXE_ICMP_HDR))));
 
 	pxe_ip_hdr(pack_out->data, iphdr->src_ip, 0x01, reply_size, 0);
 
 	/* copying all data from request packet to reply packet,
 	 * starting after headers
 	 */
-	pxe_memcpy(reply_icmphdr + 1, pack->data + iphdr_len + sizeof(pxe_icmp),
+	pxe_memcpy(reply_icmphdr + 1, pack->data + iphdr_len + sizeof(PXE_ICMP_HDR),
 	    data_size);
 
 	pxe_core_transmit(pack_out);
@@ -116,15 +116,15 @@
 }
 
 int
-pxe_ping(pxe_ipaddr *ip, int count)
+pxe_ping(PXE_IPADDR *ip, int count)
 {
 	int     scount = 0;
 
 	/* creating packet */
-	size_t		pack_size = sizeof(pxe_ip) + sizeof(pxe_icmp) + 32;
-	pxe_packet	*pack = pxe_core_alloc_packet(pack_size);
-	pxe_ip		*iphdr = NULL;
-	pxe_icmp	*icmphdr = NULL;
+	size_t		pack_size = sizeof(PXE_IP_HDR) + sizeof(PXE_ICMP_HDR) + 32;
+	PXE_PACKET	*pack = pxe_core_alloc_packet(pack_size);
+	PXE_IP_HDR	*iphdr = NULL;
+	PXE_ICMP_HDR	*icmphdr = NULL;
 
 	if (pack == NULL) {    /* failed to alloc packet */
 		return (0);
@@ -133,8 +133,8 @@
 	printf("\nping: %x, bytes=32", ip->ip);
 	pinging = ip->ip;
 
-	iphdr = (pxe_ip *)pack->data;
-	icmphdr = (pxe_icmp *)(pack->data + sizeof(pxe_ip));
+	iphdr = (PXE_IP_HDR *)pack->data;
+	icmphdr = (PXE_ICMP_HDR *)(pack->data + sizeof(PXE_IP_HDR));
 
 	/* base icmp header side*/
 	icmphdr->type = PXE_ICMP_ECHO_REQUEST;
@@ -150,7 +150,7 @@
 */
 
 	/* ip header side */
-	pxe_ip_hdr(pack->data, ip->ip, 0x01, pack_size, 0);
+	pxe_create_ip_hdr(pack->data, ip->ip, 0x01, pack_size, 0);
 
 
 	while (scount < count) {
@@ -160,8 +160,8 @@
 
 		/* recalc for every packet */
 		icmphdr->checksum = 0;
-		reply_icmphdr->checksum =
-		    ~(le2be16(pxe_ip_checksum(icmphdr, sizeof(pxe_icmp))));
+		icmphdr->checksum =
+		    ~(le2be16(pxe_ip_checksum(icmphdr, sizeof(PXE_ICMP_HDR))));
 
 		pxe_core_transmit(pack);
 
@@ -173,4 +173,4 @@
 	pinging = 0;
 
 	return (scount);
-}+}

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

@@ -10,13 +10,13 @@
  */
 
 /* ICMP header */
-typedef struct pxe_icmp {
+typedef struct pxe_icmp_hdr {
     uint8_t type;	/* type of ICMP  packet */
     uint8_t code;	/* code, used to identify session */
     uint16_t checksum;	/* ICMP header checksum */
     uint16_t packet_id;	/* for echo */
     uint16_t seq_num;   /* for echo */
-} PXE_ICMP;
+} __packed PXE_ICMP_HDR;
 
 /* pxe_ping - send icmp echo request packets to host
  *    in:
@@ -25,7 +25,7 @@
  *   out:
  *       successfull recieved echo's count
  */
-int pxe_ping(pxe_ipaddr *ip, int count);
+int pxe_ping(PXE_IPADDR *ip, int count);
 
 /* pxe_icmp_init - inits icmp protocol
  *    in:

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

@@ -28,10 +28,10 @@
  *   it may be useful later, but now it's just unused.
  */
 void
-pxe_ip_hdr(void* data, uint32_t dst_ip, uint8_t protocol,
+pxe_create_ip_hdr(void* data, uint32_t dst_ip, uint8_t protocol,
     uint16_t size, uint16_t opts_size)
 {
-	pxe_ip *iphdr = (pxe_ip *)data;
+	PXE_IP_HDR *iphdr = (PXE_IP_HDR *)data;
 
 	iphdr->checksum = 0;
 	iphdr->length = size;
@@ -50,8 +50,8 @@
          *                  0x5 [header length = 20 bytes, no opts]
          */
 	iphdr->ver_ihl = 0x45;
-	iphdr->ver_ihl += (opts_size >> 2)
+	iphdr->ver_ihl += (opts_size >> 2);
 
 	iphdr->checksum =
-	    ~le2be16(pxe_ip_chksum(data, sizeof(pxe_ip) + opts_size));
+	    ~le2be16(pxe_ip_chksum(data, sizeof(PXE_IP_HDR) + opts_size));
 }

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

@@ -5,12 +5,12 @@
 #include <stddef.h>
 
 /*
- * IP related code
+ * IP related declarations
  * reference: RFC791
  */
 
 /* IPv4 header */
-typedef struct pxe_ip {
+typedef struct pxe_ip_hdr {
 
     uint8_t     ver_ihl;        /* version & IHL (size / 4 octets)*/
     uint8_t     tos;            /* type of service */
@@ -22,7 +22,7 @@
     uint16_t    checksum;	/* header checksum */
     uint32_t    src_ip;         /* source ip address */
     uint32_t    dst_ip;         /* destination ip address */
-} PXE_ICMP;
+} __packed  PXE_IP_HDR;
 
 /* IPv4 address */
 typedef struct pxe_ipaddr {
@@ -30,14 +30,14 @@
         uint32_t ip;
         uint8_t  octet[4];
     };
-} PXE_IPADDR;
+} __packed PXE_IPADDR;
 
 
 /* calculates checksum */
 uint16_t pxe_ip_checksum(const void *data, size_t size);
 
 /* fills ip header data */
-void pxe_ip_hdr(void *data, uint32_t dst_ip, uint8_t protocol, uint16_t size,
+void pxe_create_ip_hdr(void *data, uint32_t dst_ip, uint8_t protocol, uint16_t size,
 	 uint16_t opts_size);
 
 #endif // PXE_IP_H_INCLUDED

==== //depot/projects/soc2007/taleks-pxe_http/pxe_isr.S#3 (text+ko) ====

@@ -137,7 +137,7 @@
 		pushf					# push flags
 
 /*
- *  here is calling of chained interrupt handler. Don't think it' srelly needed now
+ *  here is calling of chained interrupt handler. Don't think it's really needed now
  **
  *		pushw %es		
  *		movw chained_irq_off+2, %ax
@@ -303,7 +303,7 @@
 
 mask_int.1:	movw	%bx, %cx
 		andw	$0x07, %cx
-		movw	$0x1, %bl
+		movb	$0x1, %bl
 		shlb	%cl, %bl
 		andb	original_mask, %bl		# get the original bit for this irq
 

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

@@ -9,4 +9,6 @@
 	extern uint16_t __pxe_entry_off;        /* PXE! API entry offset */
 	extern uint16_t __pxe_entry_seg;	/* PXE! API entry segment */
 
-#endif+	extern void	__isr_install();
+	extern void	__isr_remove();
+#endif

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

@@ -4,7 +4,7 @@
  * dummy implementation. Not atomic -> really dummy
  */
 int
-pxe_mutex_own(pxe_mutex *mutex, uint32_t owner)
+pxe_mutex_own(PXE_MUTEX *mutex, uint32_t owner)
 {
 
 	if (mutex->owned == PXE_MUTEX_OWNED) {
@@ -22,7 +22,7 @@
 }
 
 int
-pxe_mutex_free(pxe_mutex *mutex, uint32_t owner)
+pxe_mutex_free(PXE_MUTEX *mutex, uint32_t owner)
 {
 
 	if (mutex->owned == PXE_MUTEX_FREE)
@@ -37,13 +37,13 @@
 }
 
 int
-pxe_mutex_wait(pxe_mutex *mutex, uint32_t owner)
+pxe_mutex_wait(PXE_MUTEX *mutex, uint32_t owner)
 {
 
 	if (mutex->owner == owner)
 		return (1);
 
-	/* hope for simebody will free mutex */
+	/* hope for somebody will free mutex */
 	while ((mutex->owned == PXE_MUTEX_OWNED)) {}
 
 	return (1);

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

@@ -6,7 +6,7 @@
 #include "pxe_mutex.h"
 
 /*
- *   synchronization primitives.
+ *   synchronization primitives. NOT USED in real mode (all synchronous)
  */
 typedef struct pxe_mutex {
 
@@ -20,8 +20,8 @@
 #define PXE_MUTEX_OWNED 0x01
 #define PXE_MUTEX_FREE  0x00
 
-int	pxe_mutex_own(pxe_mutex *mutex, uint32_t owner);
-int	pxe_mutex_free(pxe_mutex *mutex, uint32_t owner);
-int	pxe_mutex_wait(pxe_mutex *mutex, uint32_t owner);
+int	pxe_mutex_own(PXE_MUTEX *mutex, uint32_t owner);
+int	pxe_mutex_free(PXE_MUTEX *mutex, uint32_t owner);
+int	pxe_mutex_wait(PXE_MUTEX *mutex, uint32_t owner);
 
 #endif // PXE_MUTEX_H_INCLUDED

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

@@ -3,7 +3,7 @@
 #include "pxe_tcp.h"
 
 
-pxe_socket pxe_sockets[PXE_DEFAULT_SOCKETS];
+PXE_SOCKET pxe_sockets[PXE_DEFAULT_SOCKETS];
 
 int
 pxe_sockets_init()
@@ -64,7 +64,7 @@
 int
 pxe_recv(int socket, void *buf, size_t buflen)
 {
-	pxe_socket* sock = &pxe_sockets[socket];
+	PXE_SOCKET *sock = &pxe_sockets[socket];
 
 	if (sock->sendbuffer.leftbuf < buflen) {
 	}

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

@@ -25,17 +25,17 @@
 } PXE_BUFFER;
 
 typedef struct pxe_socket {
-    pxe_buffer  send_buffer;
-    pxe_buffer  recv_buffer;
+    PXE_BUFFER  send_buffer;
+    PXE_BUFFER  recv_buffer;
 
     uint32_t    sent;
     uint32_t    recv;
     uint8_t     state;
 
-    pxe_ipaddr  local_ip;
+    PXE_IPADDR  local_ip;
     uint16_t    local_port;
 
-    pxe_ipaddr  remote_ip;
+    PXE_IPADDR  remote_ip;
     uint16_t    remote_port;
 
     uint32_t    last_time_sent;


More information about the p4-projects mailing list