From: Werner Almesberger Date: Tue, 16 Apr 2013 16:55:21 +0000 (-0300) Subject: tftp.c: use symbolic constants for protocol opcodes X-Git-Tag: 24jan2021_ls180~2981 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=36613c795506867104df0e099a080eceb9696218;p=litex.git tftp.c: use symbolic constants for protocol opcodes --- diff --git a/software/bios/tftp.c b/software/bios/tftp.c index 1a34ac4c..6d796de1 100644 --- a/software/bios/tftp.c +++ b/software/bios/tftp.c @@ -6,10 +6,18 @@ #define PORT_OUT 69 #define PORT_IN 7642 +enum { + TFTP_RRQ = 1, /* Read request */ + TFTP_WRQ = 2, /* Write request */ + TFTP_DATA = 3, /* Data */ + TFTP_ACK = 4, /* Acknowledgment */ + TFTP_ERROR = 5, /* Error */ +}; + static int format_request(char *buf, const char *filename) { *buf++ = 0x00; /* Opcode: Request */ - *buf++ = 0x01; + *buf++ = TFTP_RRQ; strcpy(buf, filename); buf += strlen(filename); *buf++ = 0x00; @@ -25,7 +33,7 @@ static int format_request(char *buf, const char *filename) static int format_ack(char *buf, unsigned short block) { *buf++ = 0x00; /* Opcode: Ack */ - *buf++ = 0x04; + *buf++ = TFTP_ACK; *buf++ = (block & 0xff00) >> 8; *buf++ = (block & 0x00ff); return 4; @@ -36,7 +44,8 @@ static int total_length; static int transfer_finished; static char *dst_buffer; -static void rx_callback(unsigned int src_ip, unsigned short src_port, unsigned short dst_port, void *_data, unsigned int length) +static void rx_callback(unsigned int src_ip, unsigned short src_port, + unsigned short dst_port, void *_data, unsigned int length) { unsigned char *data = (unsigned char *)_data; unsigned short opcode; @@ -49,7 +58,7 @@ static void rx_callback(unsigned int src_ip, unsigned short src_port, unsigned s opcode = ((unsigned short)(data[0]) << 8)|((unsigned short)(data[1])); block = ((unsigned short)(data[2]) << 8)|((unsigned short)(data[3])); if(block < 1) return; - if(opcode == 3) { /* Data */ + if(opcode == TFTP_DATA) { /* Data */ length -= 4; offset = (block-1)*512; for(i=0;i