OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [boot-loader-ethmac/] [udp.c] - Diff between revs 78 and 80

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 78 Rev 80
Line 49... Line 49...
#include "packet.h"
#include "packet.h"
#include "udp.h"
#include "udp.h"
 
 
 
 
int         udp_checksum_errors_g = 0;
int         udp_checksum_errors_g = 0;
block_t*    udp_file_g = NULL;
 
block_t*    udp_current_block_g = NULL;
 
 
 
 
 
void parse_udp_packet(char * buf, packet_t* rx_packet)
void parse_udp_packet(char * buf, packet_t* rx_packet)
{
{
    unsigned int udp_src_port    = buf[0]<<8|buf[1];
    unsigned int udp_src_port    = buf[0]<<8|buf[1];
Line 86... Line 84...
    if (checksum)
    if (checksum)
        udp_checksum_errors_g++;
        udp_checksum_errors_g++;
 
 
 
 
     /* TFTP */
     /* TFTP */
    if (udp_dst_port == 69 && !checksum) {
    if (udp_dst_port == 69 && !checksum)
        unsigned int opcode = buf[8]<<8|buf[9];
        parse_tftp_packet(buf, rx_packet, udp_len-12, udp_src_port, udp_dst_port);
        unsigned int block  = buf[10]<<8|buf[11];
 
        int tftp_len = udp_len - 12;
 
 
 
        mode_offset = next_string(&buf[10]);
 
        binary_mode = strcmp("octet", &buf[10+mode_offset]);
 
 
 
        switch (opcode) {
 
 
 
            case  UDP_READ:
 
                udp_reply(rx_packet, udp_dst_port, udp_src_port, 0, UDP_ERROR);
 
                break;
 
 
 
            case  UDP_WRITE:
 
                udp_file_g = init_buffer_512();
 
                udp_file_g->filename = malloc(256);
 
                strcpy(udp_file_g->filename, &buf[10]);
 
 
 
                if (strncmp(&buf[10], "vmlinux", 7) == 0)
 
                    udp_file_g->linux_boot = 1;
 
 
 
                udp_current_block_g = udp_file_g;
 
 
 
                if (binary_mode)
 
                    udp_reply(rx_packet, udp_dst_port, udp_src_port, 0, UDP_ACK);
 
                else
 
                    udp_reply(rx_packet, udp_dst_port, udp_src_port, 0, UDP_ERROR);
 
                break;
 
 
 
 
 
            case  UDP_DATA:
 
                udp_reply(rx_packet, udp_dst_port, udp_src_port, block, UDP_ACK);
 
 
 
                if (block > udp_file_g->last_block) {
 
                    // Have not already received this block
 
                    udp_file_g->last_block = block;
 
 
 
                    /* receive and save a block */
 
                    udp_current_block_g->bytes = tftp_len;
 
                    udp_file_g->total_bytes += tftp_len;
 
                    udp_file_g->total_blocks++;
 
 
 
                    memcpy(udp_current_block_g->buf512, &buf[12], tftp_len);
 
 
 
                    /* Prepare the next block */
 
                    if (tftp_len == 512) {
 
                        udp_current_block_g->next = init_buffer_512();
 
                        udp_current_block_g = udp_current_block_g->next;
 
                        }
 
                    else { /* Last block */
 
                        udp_file_g->ready = 1;
 
                        }
 
                    }
 
                break;
 
 
 
 
 
            default: break;
 
            }
 
        }
 
}
}
 
 
 
 
 
 
void udp_reply(packet_t* rx_packet, int udp_src_port, int udp_dst_port, int block, int reply_type)
void udp_reply(packet_t* rx_packet, int udp_src_port, int udp_dst_port, int block, int reply_type)
Line 235... Line 176...
    ethernet_header(buf, &target, 0x0800);  /*bytes 0 to 13*/
    ethernet_header(buf, &target, 0x0800);  /*bytes 0 to 13*/
    tx_packet(34+udp_len);  // packet length in bytes
    tx_packet(34+udp_len);  // packet length in bytes
}
}
 
 
 
 
block_t* init_buffer_512()
 
{
 
    block_t* block = malloc(sizeof(block_t));
 
    block->buf512 = malloc(512);
 
    block->next   = NULL;
 
    block->bytes  = 0;
 
    block->last_block  = 0;
 
    block->total_bytes  = 0;
 
    block->total_blocks  = 0;
 
    block->ready  = 0;
 
    block->filename  = NULL;
 
    block->linux_boot = 0;
 
    return block;
 
}
 
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.