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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [services/] [arp.c] - Blame information for rev 1778

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
#define TIMEOUT         5               /* Seconds before trying ARP again */
32
#define TIMEOUT_COUNT   1               /* # of timeouts before giving up  */
33
 
34
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len);
35
static void ArpTimeout(void);
36
 
37
int     ArpTry = 0;
38
 
39
/*
40
 *      Handle a ARP received packet.
41
 */
42
static void
43
ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len)
44
{
45
        /* Check if the frame is really an ARP reply */
46
        if (memcmp (NetServerEther, NetBcastAddr, 6) != 0) {
47
#ifdef  DEBUG
48
                printf("Got good ARP - start TFTP\n");
49
#endif
50
                TftpStart ();
51
        }
52
}
53
 
54
 
55
/*
56
 *      Timeout on ARP request.
57
 */
58
static void
59
ArpTimeout(void)
60
{
61
        if (ArpTry >= TIMEOUT_COUNT) {
62
                printf("\nRetry count exceeded; starting again\n");
63
                NetStartAgain ();
64
        } else {
65 833 simons
                NetSetTimeout (TIMEOUT * TICKS_PER_SEC, ArpTimeout);
66 809 simons
                ArpRequest ();
67
        }
68
}
69
 
70
 
71
void
72
ArpRequest (void)
73
{
74
        int i;
75
        volatile unsigned char *pkt;
76
        ARP_t * arp;
77 1495 jcastillo
#ifdef  DEBUG
78 809 simons
        printf("ARP broadcast %d\n", ++ArpTry);
79 1495 jcastillo
#endif  
80 809 simons
        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 833 simons
            *((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP;
102 809 simons
        }
103
 
104
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
105
 
106 833 simons
        NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout);
107 809 simons
        NetSetHandler(ArpHandler);
108
}
109
 

powered by: WebSVN 2.1.0

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