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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [arp.c] - Blame information for rev 304

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

Line No. Rev Author Line
1 2 marcus.erl
/*
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 140 julius
#include "string.h"
31 2 marcus.erl
 
32
#define TIMEOUT         5               /* Seconds before trying ARP again */
33
#define TIMEOUT_COUNT   1               /* # of timeouts before giving up  */
34 140 julius
#define DEBUG // jb
35 2 marcus.erl
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 * TICKS_PER_SEC, 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
#ifdef  DEBUG
79
        printf("ARP broadcast %d\n", ++ArpTry);
80
#endif  
81
        pkt = NetTxPacket;
82
 
83
        NetSetEther(pkt, NetBcastAddr, PROT_ARP);
84
        pkt += ETHER_HDR_SIZE;
85
 
86
        arp = (ARP_t *)pkt;
87
 
88
        arp->ar_hrd = ARP_ETHER;
89
        arp->ar_pro = PROT_IP;
90
        arp->ar_hln = 6;
91
        arp->ar_pln = 4;
92
        arp->ar_op  = ARPOP_REQUEST;
93 140 julius
        NetCopyEther(&arp->ar_data[0], NetOurEther);     /* source ET addr */
94
        //*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP;   /* source IP addr */
95
        memcpy(&arp->ar_data[6], (unsigned char*) &NetOurIP, 4);
96
 
97 2 marcus.erl
        for (i=10; i<16; ++i) {
98 140 julius
                arp->ar_data[i] = 0;                     /* dest ET addr = 0*/
99 2 marcus.erl
        }
100
 
101
        if((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
102 140 julius
          //*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP;
103
          memcpy(&arp->ar_data[16], (unsigned char*) &NetOurGatewayIP,
104
                 sizeof(IPaddr_t));
105 2 marcus.erl
        } else {
106 140 julius
          //*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP;
107
          memcpy(&arp->ar_data[16], (unsigned char*) &NetServerIP,
108
                 sizeof(IPaddr_t));
109 2 marcus.erl
        }
110
 
111
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
112
 
113
        NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout);
114
        NetSetHandler(ArpHandler);
115
}
116
 

powered by: WebSVN 2.1.0

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