aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 17:52:02 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 17:52:02 +0800
commitc06e14e0253243a56a1ef5c583d271af779f4ee4 (patch)
tree1ea31ed6207f3f54f7210e28f08be4ac415d217e
parent6b4f3fc3da75f94997673893dfeac254e3044056 (diff)
downloadpxelinux-c06e14e0253243a56a1ef5c583d271af779f4ee4.tar.gz
pxelinux-c06e14e0253243a56a1ef5c583d271af779f4ee4.tar.xz
pxelinux-c06e14e0253243a56a1ef5c583d271af779f4ee4.zip
Core:PXELINUX: code clean -- 3
-rw-r--r--core/pxe.c135
1 files changed, 52 insertions, 83 deletions
diff --git a/core/pxe.c b/core/pxe.c
index 8af03c3a..1e12544e 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -832,29 +832,23 @@ int pxe_call(int opcode, void *data)
*
* Send ACK packet. This is a common operation and so is worth canning.
*
- * Entry:
- * SI = TFTP block
- * AX = Packet # to ack (network byte order)
- * Exit:
- * All regiseters preserved
- * This function uses the pxe_udp_write_pkt but not the packet_buf
- *
+ * @param: file, TFTP block pointer
+ * @param: ack_num, Packet # to ack (network byte order)
+ *
*/
-void ack_packet(com32sys_t *regs)
+void ack_packet(struct open_file_t *file, uint16_t ack_num)
{
- extern void pxenv(void);
int err;
struct pxe_udp_write_pkt *uw_pkt = (struct pxe_udp_write_pkt *)pxe_udp_write_pkt;;
- struct open_file_t *file = MK_PTR(0, regs->esi.w[0]);
-
+
/* Packet number to ack */
- ack_packet_buf[1] = regs->eax.w[0];
+ ack_packet_buf[1] = ack_num;
uw_pkt->lport = file->tftp_localport;
uw_pkt->rport = file->tftp_remoteport;
uw_pkt->sip = file->tftp_remoteip;
uw_pkt->gip = ((uw_pkt->sip ^ MyIP) & Netmask) ? Gateway : 0;
uw_pkt->buffer[0] = OFFS_WRT(ack_packet_buf, 0);
- uw_pkt->buffer[1] = 0; /* seems SEG and OFFS stuff doesn't work here */
+ uw_pkt->buffer[1] = 0; /* seems SEG and OFFS stuff doesn't work here */
uw_pkt->buffersize = 4;
err = pxe_call(PXENV_UDP_WRITE, uw_pkt);
@@ -864,18 +858,15 @@ void ack_packet(com32sys_t *regs)
}
-/*
+/**
* Get a DHCP packet from the PXE stack into the trackbuf
*
- * Input:
- * DL = packet type
- * Output:
- * CX = buffer size
+ * @param: type, packet type
+ * @return: buffer size
*
*/
-void pxe_get_cached_info(com32sys_t *regs)
+int pxe_get_cached_info(int type)
{
- int type = regs->edx.b[0];
int err;
struct pxe_bootp_query_pkt *bq_pkt = (struct pxe_bootp_query_pkt *)pxe_bootp_query_pkt;
printf(" %02x", type);
@@ -889,10 +880,10 @@ void pxe_get_cached_info(com32sys_t *regs)
err = pxe_call(PXENV_GET_CACHED_INFO, bq_pkt);
if (err) {
printf("%s %04x\n", err_pxefailed, err);
- call16(kaboom, regs, regs);
+ call16(kaboom, NULL, NULL);
}
-
- regs->ecx.w[0] = bq_pkt->buffersize;
+
+ return bq_pkt->buffersize;
}
/*
@@ -1000,14 +991,10 @@ void local_domain(void *data, int opt_len)
void vendor_encaps(void *data, int opt_len)
{
- extern void parse_dhcp_options(com32sys_t *);
- com32sys_t regs;
-
- memset(&regs, 0 ,sizeof regs);
- regs.edx.b[1] = 208; /* Only recongnize PXELINUX options */
- regs.ecx.w[0] = opt_len;
- regs.esi.w[0] = OFFS_WRT(data, 0);
- parse_dhcp_options(&regs);
+ extern void parse_dhcp_options(void *, int, int);
+
+ /* Only recongnize PXELINUX options */
+ parse_dhcp_options(data, opt_len, 208);
}
void option_overload(void *data, int opt_len)
@@ -1111,30 +1098,28 @@ struct dhcp_options dhcp_opts[] = {
};
/*
- ; Parse a sequence of DHCP options, pointed to by DS:SI; the field
- ; size is CX -- some DHCP servers leave option fields unterminated
- ; in violation of the spec.
- ;
- ; For parse_some_dhcp_options, DH contains the minimum value for
- ; the option to recognize -- this is used to restrict parsing to
- ; PXELINUX-specific options only.
-*/
-void parse_dhcp_options(com32sys_t *regs)
+ * Parse a sequence of DHCP options, pointed to by _option_;
+ * -- some DHCP servers leave option fields unterminated
+ * in violation of the spec.
+ *
+ * filter contains the minimum value for the option to recognize
+ * -- this is used to restrict parsing to PXELINUX-specific options only.
+ */
+void parse_dhcp_options(void *option, int size, int filter)
{
- int size = regs->ecx.w[0];
- char *option = (char *)MK_PTR(regs->ds, regs->esi.w[0]);
uint8_t opt_num;
uint8_t opt_len;
- uint8_t opt_filter = regs->edx.b[1] == 208 ? 208 : 0;
+ uint8_t opt_filter = filter == 208 ? 208 : 0;
int opt_entries = sizeof(dhcp_opts) / sizeof(dhcp_opts[0]);
int i = 0;
+ char *p = option;
struct dhcp_options *opt;
if (opt_filter)
printf("***NOTE!:*** we hit a pxelinux-specific options\n");
while (size --) {
- opt_num = *option++;
+ opt_num = *p++;
if (!size)
break;
@@ -1144,7 +1129,7 @@ void parse_dhcp_options(com32sys_t *regs)
break;
/* Anything else will have a lenght filed */
- opt_len = *option++; /* c <- option lenght */
+ opt_len = *p++; /* c <- option lenght */
size = size - opt_len - 1;
if (size < 0)
break;
@@ -1156,14 +1141,14 @@ void parse_dhcp_options(com32sys_t *regs)
opt = dhcp_opts;
for (i = 0; i < opt_entries; i++) {
if (opt_num == opt->opt_num) {
- opt->fun(option, opt_len);
+ opt->fun(p, opt_len);
break;
}
opt ++;
}
/* parse next */
- option += opt_len;
+ p += opt_len;
}
}
@@ -1191,10 +1176,9 @@ void parse_dhcp_options(com32sys_t *regs)
; of the packet in in CX on entry.
;
*/
-void parse_dhcp(com32sys_t *regs)
+void parse_dhcp(int pkt_len)
{
struct bootp_t *dhcp = (struct bootp_t *)trackbuf;
- int pkt_len = regs->ecx.w[0];
int opt_len;
OverLoad = 0;
@@ -1205,25 +1189,16 @@ void parse_dhcp(com32sys_t *regs)
ServerIP = dhcp->sip;
opt_len = (char *)dhcp + pkt_len - (char *)&dhcp->options;
- if (opt_len && (dhcp->option_magic == BOOTP_OPTION_MAGIC)) {
- regs->ecx.w[0] = opt_len;
- regs->esi.w[0] = OFFS_WRT(&dhcp->options, 0);
- parse_dhcp_options(regs);
- }
+ if (opt_len && (dhcp->option_magic == BOOTP_OPTION_MAGIC))
+ parse_dhcp_options(&dhcp->options, opt_len, 0);
- if (OverLoad & 1) {
- regs->ecx.w[0] = 128;
- regs->esi.w[0] = OFFS_WRT(&dhcp->bootfile, 0);
- parse_dhcp_options(regs);
- } else if (dhcp->bootfile[0]) {
+ if (OverLoad & 1)
+ parse_dhcp_options(&dhcp->bootfile, 128, 0);
+ else if (dhcp->bootfile[0])
strcpy(BootFile, dhcp->bootfile);
- }
-
- if (OverLoad & 2) {
- regs->ecx.w[0] = 64;
- regs->esi.w[0] = OFFS_WRT(dhcp->sname, 0);
- parse_dhcp_options(regs);
- }
+
+ if (OverLoad & 2)
+ parse_dhcp_options(dhcp->sname, 64, 0);
}
#if GPXE
@@ -1336,8 +1311,7 @@ void fill_buffer(com32sys_t *regs)
* the next packet to be sent.
*/
ack_again:
- regs->eax.w[0] = file->tftp_lastpkt;
- ack_packet(regs);
+ ack_packet(file, file->tftp_lastpkt);
timeout_ptr = TimeoutTable;
timeout = *timeout_ptr++;
@@ -1406,8 +1380,7 @@ void fill_buffer(com32sys_t *regs)
file->tftp_bytesleft = buffersize;
if (buffersize < file->tftp_blksize) {
/* it's the last block, ACK packet immediately */
- regs->eax.w[0] = *(uint16_t *)(data + 2);
- ack_packet(regs);
+ ack_packet(file, *(uint16_t *)(data + 2));
/* Make sure we know we are at end of file */
file->tftp_filesize = file->tftp_filepos;
@@ -1926,9 +1899,7 @@ void searchdir_c(com32sys_t *regs)
*/
file->tftp_filesize = buffersize;
file->tftp_goteof = 1;
- regs->eax.w[0] = blk_num;
- regs->esi.w[0] = OFFS_WRT(file, 0);
- ack_packet(regs);
+ ack_packet(file, blk_num);
}
file->tftp_bytesleft = buffersize;
@@ -2034,9 +2005,10 @@ void searchdir_c(com32sys_t *regs)
/*
* Network-specific initialization
*/
-void network_init(com32sys_t *regs)
+void network_init()
{
struct bootp_t *bp = (struct bootp_t *)trackbuf;
+ int pkt_len;
*LocalDomain = 0; /* No LocalDomain received */
@@ -2044,9 +2016,8 @@ void network_init(com32sys_t *regs)
* Get the DHCP client identifiers (query info 1)
*/
printf("%s", get_packet_msg);
- regs->edx.b[0] = 1;
- pxe_get_cached_info(regs);
- parse_dhcp(regs);
+ pkt_len = pxe_get_cached_info(1);
+ parse_dhcp(pkt_len);
/*
; We don't use flags from the request packet, so
; this is a good time to initialize DHCPMagic...
@@ -2063,9 +2034,8 @@ void network_init(com32sys_t *regs)
* Get the BOOTP/DHCP packet that brought us file (and an IP
* address). This lives in the DHCPACK packet (query info 2)
*/
- regs->edx.b[0] = 2;
- pxe_get_cached_info(regs);
- parse_dhcp(regs);
+ pkt_len = pxe_get_cached_info(2);
+ parse_dhcp(pkt_len);
/*
* Save away MAC address (assume this is in query info 2. If this
* turns out to be problematic it might be better getting it from
@@ -2080,9 +2050,8 @@ void network_init(com32sys_t *regs)
* Get the boot file and other info. This lives in the CACHED_REPLY
* packet (query info 3)
*/
- regs->edx.b[0] = 3;
- pxe_get_cached_info(regs);
- parse_dhcp(regs);
+ pkt_len = pxe_get_cached_info(3);
+ parse_dhcp(pkt_len);
printf("\n");