OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [trunk/] [sw/] [dev/] [test_bfm/] [ether/] [ether_rx.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 kuzmi4
//////////////////////////////////////////////////////////////////////////////////
2
#include <stdlib.h>
3
#include <stdio.h>
4
 
5
#include "ether.h" // ETH_PKT_MAC_ADDR_LEN, ..
6
#include "eth_host_bfm.h" // eth_frm_read_wait, ..
7
 
8
//////////////////////////////////////////////////////////////////////////////////
9
// PKT-LEN
10
int pkt_len;
11
//////////////////////////////////////////////////////////////////////////////////
12
// 
13
// Ethernet RX routine
14
//
15
 
16
int ether_rx_ok(void)
17
{
18
    eth_frm_read_len(&pkt_len);
19
    return(pkt_len != -1);
20
}
21
 
22
void ether_rx(char *obuff, int *olen) // !!!only after 'ether_rx_ok' + 'obuff' must be pre-allocated
23
{
24
    // dec vars
25
    int i, pkt_data;
26
    // proc
27
    *olen = pkt_len;
28
    for (i = 0; i < pkt_len; i++) {
29
            eth_frm_read(&pkt_data, i);
30
            *(obuff+i) = pkt_data;
31
    }
32
    // msg2usr
33
    unsigned short pkt_type = *((unsigned short *)((obuff)+ETH_PKT_MAC_ADDR_LEN*2));
34
    switch(pkt_type) {
35
        case ETH_PKT_ARP : {
36
            printf("ether_rx: ETH_PKT_ARP, len=%04x\n", pkt_len);
37
            break;
38
        }
39
        case ETH_PKT_IPv4 : {
40
            ip_hdr_t *ptr_ipv4_hdr = (ip_hdr_t *)(obuff+ETH_HDR_LEN);
41
            switch(ptr_ipv4_hdr->ip_prot) {
42
                case IPv4_ICMP : {
43
                    printf("ether_rx: ETH_PKT_IPv4-ICMP, len=%04x\n", pkt_len);
44
                    break;
45
                }
46
                case IPv4_UDP : {
47
                    printf("ether_rx: ETH_PKT_IPv4-UDP, len=%04x\n", pkt_len);
48
                    break;
49
                }
50
                default : {
51
                    printf("ether_rx: ETH_PKT_IPv4: IP protocol number = %x, len=%04x\n", ptr_ipv4_hdr->ip_prot, pkt_len);
52
                    break;
53
                }
54
            }
55
            break;
56
        }
57
        default : {
58
            printf("ether_rx: pkt-type=%04x, len=%04x\n", ntohs(pkt_type), pkt_len);
59
            break;
60
        }
61
    }
62
}
63
//////////////////////////////////////////////////////////////////////////////////

powered by: WebSVN 2.1.0

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