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

Subversion Repositories amber

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

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
 
138
    /* 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
 
145
    /* TCP */
146
    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
 
157
    /* Telnet */
158
    unsigned int    telnet_payload_len;
159
} packet_t;
160
 
161
 
162
 
163
typedef struct {
164
 
165
    packet_buffer_t** tcp_buf;
166
    int          tcp_current_buf;
167
 
168
    /* Telnet rx and tx line buffers */
169
    line_buf_t*  telnet_rxbuf;
170
    line_buf_t*  telnet_txbuf;
171
 
172
    int          telnet_sent_opening_message;
173
    int          telnet_echo_mode;
174
    int          telnet_connection_state;
175
    int          telnet_options_sent;
176
 
177
    int          packets_sent;
178
    int          packets_received;
179
    int          packets_resent;
180
 
181
    int          tcp_connection_state;
182
    int          tcp_reset;
183
    int          tcp_disconnect;
184
    int          tcp_seq;            /* should be random initial seq number for tcp */
185
    int          tcp_last_seq;
186
    unsigned int tcp_last_ack;
187
 
188
    int          id;
189
 
190
    packet_t*    rx_packet;  /* Header info from last packet received */
191
} socket_t;
192
 
193
 
194
 
195
/* Enumerated types */
196
enum mdi_ctrl {
197
        mdi_write = 0x04000000,
198
        mdi_read  = 0x08000000,
199
        mdi_ready = 0x10000000,
200
};
201
 
202
 
203
 
204
enum telnet_state {
205
        TELNET_CLOSED    = 0,
206
        TELNET_OPEN      = 1
207
};
208
 
209
 
210
/* Global Variables */
211
extern mac_ip_t    self_g;
212
extern packet_t*   rx_packet_g;
213
extern socket_t*   socket0_g;
214
extern socket_t*   socket1_g;
215
 
216
 
217
/* Functions */
218
void            init_packet_buffers     (socket_t*);
219
unsigned short  header_checksum16       (unsigned char *buf, unsigned short len, unsigned int sum);
220
 
221
void            arp_reply               (char *buf, mac_ip_t*);
222
void            ping_reply              (packet_t* packet0, int ping_id, int ping_seq, char * rx_buf);
223
 
224
void            ethernet_header         (char *buf, mac_ip_t* target, unsigned short type);
225
void            ip_header               (char *buf, mac_ip_t* target, unsigned short ip_len, char ip_proto);
226
 
227
void            parse_rx_packet         (char*, packet_t*);
228
void            parse_arp_packet        (char*);
229
void            parse_ip_packet         (char*, packet_t*);
230
void            parse_ping_packet       (char*, packet_t*);
231
 
232
socket_t*       init_socket             (int);
233
 
234
 
235
 
236
 
237
 
238
 

powered by: WebSVN 2.1.0

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