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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [rarp.c] - Blame information for rev 375

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 "net.h"
26
#include "bootp.h"
27
#include "rarp.h"
28
#include "tftp.h"
29
 
30
#if (CONFIG_COMMANDS & CFG_CMD_NET)
31
 
32
#define TIMEOUT         5               /* Seconds before trying BOOTP again */
33
#define TIMEOUT_COUNT   1               /* # of timeouts before giving up    */
34
 
35
 
36
int             RarpTry;
37
 
38
/*
39
 *      Handle a RARP received packet.
40
 */
41
static void
42
RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
43
{
44
#ifdef  DEBUG
45
        printf("Got good RARP\n");
46
#endif
47
        TftpStart ();
48
}
49
 
50
 
51
/*
52
 *      Timeout on BOOTP request.
53
 */
54
static void
55
RarpTimeout(void)
56
{
57
        if (RarpTry >= TIMEOUT_COUNT) {
58
                puts ("\nRetry count exceeded; starting again\n");
59
                NetStartAgain ();
60
        } else {
61
                NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout);
62
                RarpRequest ();
63
        }
64
}
65
 
66
 
67
void
68
RarpRequest (void)
69
{
70
        int i;
71
        volatile uchar *pkt;
72
        ARP_t * rarp;
73
 
74
        printf("RARP broadcast %d\n", ++RarpTry);
75
        pkt = NetTxPacket;
76
 
77
        NetSetEther(pkt, NetBcastAddr, PROT_RARP);
78
        pkt += ETHER_HDR_SIZE;
79
 
80
        rarp = (ARP_t *)pkt;
81
 
82
        rarp->ar_hrd = ARP_ETHER;
83
        rarp->ar_pro = PROT_IP;
84
        rarp->ar_hln = 6;
85
        rarp->ar_pln = 4;
86
        rarp->ar_op  = RARPOP_REQUEST;
87
        NetCopyEther(&rarp->ar_data[0], NetOurEther);    /* source ET addr */
88
        *(IPaddr_t *)(&rarp->ar_data[6]) = NetOurIP;    /* source IP addr */
89
        NetCopyEther(&rarp->ar_data[10], NetOurEther);  /* dest ET addr = source ET addr ??*/
90
        /* dest. IP addr set to broadcast */
91
        for (i = 0; i <= 3; i++) {
92
                rarp->ar_data[16 + i] = 0xff;
93
        }
94
 
95
        NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
96
 
97
        NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
98
        NetSetHandler(RarpHandler);
99
}
100
 
101
#endif /* CFG_CMD_NET */

powered by: WebSVN 2.1.0

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