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

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [boot-loader-ethmac/] [packet.h] - Blame information for rev 80

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 61 csantifort
/*----------------------------------------------------------------
2
//                                                              //
3
//  boot-loader.h                                               //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Defines for the boot-loader application.                    //
10
//                                                              //
11
//  Author(s):                                                  //
12
//      - Conor Santifort, csantifort.amber@gmail.com           //
13
//                                                              //
14
//////////////////////////////////////////////////////////////////
15
//                                                              //
16
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
17
//                                                              //
18
// This source file may be used and distributed without         //
19
// restriction provided that this copyright statement is not    //
20
// removed from the file and that any derivative work contains  //
21
// the original copyright notice and the associated disclaimer. //
22
//                                                              //
23
// This source file is free software; you can redistribute it   //
24
// and/or modify it under the terms of the GNU Lesser General   //
25
// Public License as published by the Free Software Foundation; //
26
// either version 2.1 of the License, or (at your option) any   //
27
// later version.                                               //
28
//                                                              //
29
// This source is distributed in the hope that it will be       //
30
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
31
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
32
// PURPOSE.  See the GNU Lesser General Public License for more //
33
// details.                                                     //
34
//                                                              //
35
// You should have received a copy of the GNU Lesser General    //
36
// Public License along with this source; if not, download it   //
37
// from http://www.opencores.org/lgpl.shtml                     //
38
//                                                              //
39
----------------------------------------------------------------*/
40
#define TELNET_PORT         23
41
 
42
#define MAX_PACKET_SIZE     2000
43
#define ETHMAC_RX_BUFFERS   8
44
#define TCP_TX_BUFFERS      256
45
 
46
#define TELNET_WILL 251
47
#define TELNET_WONT 252
48
#define TELNET_DO   253
49
#define TELNET_DONT 254
50
 
51
#define UDP_READ  1
52
#define UDP_WRITE 2
53
#define UDP_DATA  3
54
#define UDP_ACK   4
55
#define UDP_ERROR 5
56
 
57
 
58
/* Generic MII registers. */
59
/* Taken from kernel source file include/linux/mii.h */
60
#define MII_BMCR            0x00        /* Basic mode control register */
61
#define MII_BMSR            0x01        /* Basic mode status register  */
62
#define MII_PHYSID1         0x02        /* PHYS ID 1                   */
63
#define MII_PHYSID2         0x03        /* PHYS ID 2                   */
64
#define MII_ADVERTISE       0x04        /* Advertisement control reg   */
65
#define MII_LPA             0x05        /* Link partner ability reg    */
66
#define MII_EXPANSION       0x06        /* Expansion register          */
67
#define MII_CTRL1000        0x09        /* 1000BASE-T control          */
68
#define MII_STAT1000        0x0a        /* 1000BASE-T status           */
69
#define MII_ESTATUS         0x0f        /* Extended Status */
70
#define MII_DCOUNTER        0x12        /* Disconnect counter          */
71
#define MII_FCSCOUNTER      0x13        /* False carrier counter       */
72
#define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
73
#define MII_RERRCOUNTER     0x15        /* Receive error counter       */
74
#define MII_SREVISION       0x16        /* Silicon revision            */
75
#define MII_RESV1           0x17        /* Reserved...                 */
76
#define MII_LBRERROR        0x18        /* Lpback, rx, bypass error    */
77
#define MII_PHYADDR         0x19        /* PHY address                 */
78
#define MII_RESV2           0x1a        /* Reserved...                 */
79
#define MII_TPISTATUS       0x1b        /* TPI status for 10mbps       */
80
#define MII_NCONFIG         0x1c        /* Network interface config    */
81
 
82
/* Basic mode control register. */
83
/* Taken from kernel source file include/linux/mii.h */
84
#define BMCR_RESV               0x003f  /* Unused...                   */
85
#define BMCR_SPEED1000          0x0040  /* MSB of Speed (1000)         */
86
#define BMCR_CTST               0x0080  /* Collision test              */
87
#define BMCR_FULLDPLX           0x0100  /* Full duplex                 */
88
#define BMCR_ANRESTART          0x0200  /* Auto negotiation restart    */
89
#define BMCR_ISOLATE            0x0400  /* Disconnect DP83840 from MII */
90
#define BMCR_PDOWN              0x0800  /* Powerdown the DP83840       */
91
#define BMCR_ANENABLE           0x1000  /* Enable auto negotiation     */
92
#define BMCR_SPEED100           0x2000  /* Select 100Mbps              */
93
#define BMCR_LOOPBACK           0x4000  /* TXD loopback bits           */
94
#define BMCR_RESET              0x8000  /* Reset the DP83840           */
95
 
96
/* Basic mode status register. */
97
/* Taken from kernel source file include/linux/mii.h */
98
#define BMSR_ERCAP              0x0001  /* Ext-reg capability          */
99
#define BMSR_JCD                0x0002  /* Jabber detected             */
100
#define BMSR_LSTATUS            0x0004  /* Link status                 */
101
#define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
102
#define BMSR_RFAULT             0x0010  /* Remote fault detected       */
103
#define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
104
#define BMSR_RESV               0x00c0  /* Unused...                   */
105
#define BMSR_ESTATEN            0x0100  /* Extended Status in R15 */
106
#define BMSR_100HALF2           0x0200  /* Can do 100BASE-T2 HDX */
107
#define BMSR_100FULL2           0x0400  /* Can do 100BASE-T2 FDX */
108
#define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
109
#define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
110
#define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
111
#define BMSR_100FULL            0x4000  /* Can do 100mbps, full-duplex */
112
#define BMSR_100BASE4           0x8000  /* Can do 100mbps, 4k packets  */
113
 
114
 
115
typedef struct {
116
    unsigned char mac[6];
117
    unsigned char ip[4];
118
} mac_ip_t;
119
 
120
 
121
typedef struct {
122
    unsigned int payload_valid;
123
    unsigned int starting_seq;
124
    unsigned int ending_seq;
125
    unsigned int len_bytes;
126
    unsigned int ack_received;
127
    time_t       resend_time;
128
    char         buf[MAX_PACKET_SIZE];
129
} packet_buffer_t;
130
 
131
 
132
typedef struct {
133
    /* Ethernet */
134
    unsigned char   src_mac[6];
135
    unsigned char   dst_mac[6];
136
    unsigned int    eth_type;
137 80 csantifort
 
138 61 csantifort
    /* IPv4 */
139
    unsigned char   src_ip[4];
140
    unsigned char   dst_ip[4];
141
    unsigned int    ip_len;        // IP; in bytres
142
    unsigned int    ip_header_len; // IP; in 32-bit words
143
    unsigned int    ip_proto;
144 80 csantifort
 
145
    /* TCP */
146 61 csantifort
    unsigned int    tcp_src_port;
147
    unsigned int    tcp_dst_port;
148
    unsigned int    tcp_hdr_len;
149
    unsigned int    tcp_seq;
150
    unsigned int    tcp_ack;
151
    unsigned int    tcp_flags;
152
    unsigned int    tcp_window_size;
153
    unsigned int    tcp_len;
154
    unsigned int    tcp_payload_len;
155
    unsigned int    tcp_src_time_stamp;
156 80 csantifort
 
157 61 csantifort
    /* Telnet */
158
    unsigned int    telnet_payload_len;
159
} packet_t;
160
 
161
 
162
 
163
/* Enumerated types */
164
enum mdi_ctrl {
165
        mdi_write = 0x04000000,
166
        mdi_read  = 0x08000000,
167
        mdi_ready = 0x10000000,
168
};
169
 
170
 
171
 
172
enum telnet_state {
173
        TELNET_CLOSED    = 0,
174
        TELNET_OPEN      = 1
175
};
176
 
177
 
178
/* Global Variables */
179
extern mac_ip_t    self_g;
180
 
181
 
182
/* Functions */
183 80 csantifort
void            init_packet             ();
184 61 csantifort
unsigned short  header_checksum16       (unsigned char *buf, unsigned short len, unsigned int sum);
185
 
186
void            arp_reply               (char *buf, mac_ip_t*);
187
void            ping_reply              (packet_t* packet0, int ping_id, int ping_seq, char * rx_buf);
188
 
189
void            ethernet_header         (char *buf, mac_ip_t* target, unsigned short type);
190
void            ip_header               (char *buf, mac_ip_t* target, unsigned short ip_len, char ip_proto);
191
 
192
void            parse_rx_packet         (char*, packet_t*);
193
void            parse_arp_packet        (char*);
194
void            parse_ip_packet         (char*, packet_t*);
195
void            parse_ping_packet       (char*, packet_t*);
196
 
197
 
198
 
199
 
200
 
201
 

powered by: WebSVN 2.1.0

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