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

Subversion Repositories amber

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

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 81 csantifort
 
122 61 csantifort
typedef struct {
123 81 csantifort
    unsigned char ip[4];
124
} ip_t;
125
 
126
 
127
typedef struct {
128
    unsigned char mac[6];
129
    unsigned char stuffing[2]; /* word aligned */
130
} mac_t;
131
 
132
 
133
typedef struct {
134 61 csantifort
    unsigned int payload_valid;
135
    unsigned int starting_seq;
136
    unsigned int ending_seq;
137
    unsigned int len_bytes;
138
    unsigned int ack_received;
139
    time_t       resend_time;
140
    char         buf[MAX_PACKET_SIZE];
141
} packet_buffer_t;
142
 
143
 
144
typedef struct {
145
    /* Ethernet */
146
    unsigned char   src_mac[6];
147
    unsigned char   dst_mac[6];
148
    unsigned int    eth_type;
149 80 csantifort
 
150 61 csantifort
    /* IPv4 */
151
    unsigned char   src_ip[4];
152
    unsigned char   dst_ip[4];
153
    unsigned int    ip_len;        // IP; in bytres
154
    unsigned int    ip_header_len; // IP; in 32-bit words
155
    unsigned int    ip_proto;
156 80 csantifort
 
157
    /* TCP */
158 61 csantifort
    unsigned int    tcp_src_port;
159
    unsigned int    tcp_dst_port;
160
    unsigned int    tcp_hdr_len;
161
    unsigned int    tcp_seq;
162
    unsigned int    tcp_ack;
163
    unsigned int    tcp_flags;
164
    unsigned int    tcp_window_size;
165 81 csantifort
 
166
    /* the TCP that sent this option will right-shift its true
167
       receive-window values by 'shift.cnt' bits for transmission in
168
       SEG.WND. */
169
    unsigned int    tcp_window_scale;
170
 
171 61 csantifort
    unsigned int    tcp_len;
172
    unsigned int    tcp_payload_len;
173
    unsigned int    tcp_src_time_stamp;
174 80 csantifort
 
175 61 csantifort
    /* Telnet */
176
    unsigned int    telnet_payload_len;
177
} packet_t;
178
 
179
 
180
 
181
/* Enumerated types */
182
enum mdi_ctrl {
183
        mdi_write = 0x04000000,
184
        mdi_read  = 0x08000000,
185
        mdi_ready = 0x10000000,
186
};
187
 
188
 
189
 
190
enum telnet_state {
191
        TELNET_CLOSED    = 0,
192
        TELNET_OPEN      = 1
193
};
194
 
195
 
196
/* Global Variables */
197
extern mac_ip_t    self_g;
198
 
199
 
200
/* Functions */
201 80 csantifort
void            init_packet             ();
202 61 csantifort
unsigned short  header_checksum16       (unsigned char *buf, unsigned short len, unsigned int sum);
203
 
204 81 csantifort
void            arp_reply               (mac_t*, ip_t*);
205 61 csantifort
void            ping_reply              (packet_t* packet0, int ping_id, int ping_seq, char * rx_buf);
206
 
207 81 csantifort
void            ethernet_header         (char*, mac_t*, unsigned short);
208
void            ip_header               (char*, ip_t*, unsigned short, char);
209 61 csantifort
 
210
void            parse_rx_packet         (char*, packet_t*);
211
void            parse_arp_packet        (char*);
212
void            parse_ip_packet         (char*, packet_t*);
213
void            parse_ping_packet       (char*, packet_t*);
214
 
215
 
216
 
217
 
218
 
219
 

powered by: WebSVN 2.1.0

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