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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [orpmon/] [services/] [arp.c] - Blame information for rev 809

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

Line No. Rev Author Line
1 809 simons
/*
2
 * (C) Copyright 2000
3
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4
 *
5
 * See file CREDITS for list of people who contributed to this
6
 * project.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License as
10
 * published by the Free Software Foundation; either version 2 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21
 * MA 02111-1307 USA
22
 */
23
 
24
#include "common.h"
25
#include "support.h"
26
#include "net.h"
27
#include "bootp.h"
28
#include "tftp.h"
29
#include "arp.h"
30
 
31
 
32
#define TIMEOUT         5               /* Seconds before trying ARP again */
33
#define TIMEOUT_COUNT   1               /* # of timeouts before giving up  */
34
 
35
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len);
36
static void ArpTimeout(void);
37
 
38
int     ArpTry = 0;
39
 
40
/*
41
 *      Handle a ARP received packet.
42
 */
43
static void
44
ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len)
45
{
46
        /* Check if the frame is really an ARP reply */
47
        if (memcmp (NetServerEther, NetBcastAddr, 6) != 0) {
48
#ifdef  DEBUG
49
                printf("Got good ARP - start TFTP\n");
50
#endif
51
                TftpStart ();
52
        }
53
}
54
 
55
 
56
/*
57
 *      Timeout on ARP request.
58
 */
59
static void
60
ArpTimeout(void)
61
{
62
        if (ArpTry >= TIMEOUT_COUNT) {
63
                printf("\nRetry count exceeded; starting again\n");
64
                NetStartAgain ();
65
        } else {
66
                NetSetTimeout (TIMEOUT * IN_CLK, ArpTimeout);
67
                ArpRequest ();
68
        }
69
}
70
 
71
 
72
void
73
ArpRequest (void)
74
{
75
        int i;
76
        volatile unsigned char *pkt;
77
        ARP_t * arp;
78
 
79
        printf("ARP broadcast %d\n", ++ArpTry);
80
        pkt = NetTxPacket;
81
 
82
        NetSetEther(pkt, NetBcastAddr, PROT_ARP);
83
        pkt += ETHER_HDR_SIZE;
84
 
85
        arp = (ARP_t *)pkt;
86
 
87
        arp->ar_hrd = ARP_ETHER;
88
        arp->ar_pro = PROT_IP;
89
        arp->ar_hln = 6;
90
        arp->ar_pln = 4;
91
        arp->ar_op  = ARPOP_REQUEST;
92
        NetCopyEther(&arp->ar_data[0], NetOurEther);     /* source ET addr       */
93
        *(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP;     /* source IP addr       */
94
        for (i=10; i<16; ++i) {
95
                arp->ar_data[i] = 0;                     /* dest ET addr = 0     */
96
        }
97
 
98
        if((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
99
            *(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP;
100
        } else {
101
            *(IPaddr_t *)(&arp->ar_data[16]) = NetServerIP;
102
        }
103
 
104
 
105
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
106
 
107
        NetSetTimeout(TIMEOUT * IN_CLK, ArpTimeout);
108
        NetSetHandler(ArpHandler);
109
}
110
 

powered by: WebSVN 2.1.0

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