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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [common/] [current/] [tests/] [set_mac_address.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/set_mac_address.c
4
//
5
//      Set_Mac_Address Utility - this carefully does NOTHING unless you
6
//      edit this source file to confirm that you really want to do it.
7
//
8
//==========================================================================
9
// ####BSDALTCOPYRIGHTBEGIN####                                             
10
// -------------------------------------------                              
11
// Portions of this software may have been derived from FreeBSD, OpenBSD,   
12
// or other sources, and if so are covered by the appropriate copyright     
13
// and license included herein.                                             
14
// -------------------------------------------                              
15
// ####BSDALTCOPYRIGHTEND####                                               
16
//==========================================================================
17
//#####DESCRIPTIONBEGIN####
18
//
19
// Author(s):    hmt
20
// Contributors: 
21
// Date:         2000-05-03
22
// Purpose:      
23
// Description:  
24
//              
25
//
26
//####DESCRIPTIONEND####
27
//
28
//==========================================================================
29
 
30
#include <pkgconf/system.h>
31
#ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
32
#include CYGBLD_DEVS_ETH_DEVICE_H
33
#endif
34
 
35
 
36
// SET_MAC_ADDRESS test code
37
 
38
#include <network.h>
39
 
40
#include <netinet/if_ether.h>
41
 
42
#define NUMTHREADS 1
43
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
44
static char thread_stack[NUMTHREADS][STACK_SIZE];
45
static cyg_thread thread_data[NUMTHREADS];
46
static cyg_handle_t thread_handle[NUMTHREADS];
47
 
48
extern void
49
cyg_test_exit(void);
50
 
51
void
52
pexit(char *s)
53
{
54
    perror(s);
55
    cyg_test_exit();
56
}
57
 
58
// ------------------------------------------------------------------------
59
// remove NT to make this utility be useful ;-)
60
#define DONT_SET_ETH0
61
#define DONT_SET_ETH1
62
 
63
// These are commented out to make sure you choose a value:
64
#ifdef DO_SET_ETH0
65
//static cyg_uint8 new_eth0_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdd};
66
//static cyg_uint8 new_eth0_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdb};
67
#endif
68
#ifdef DO_SET_ETH1
69
//static cyg_uint8 new_eth1_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xde};
70
//static cyg_uint8 new_eth1_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdc};
71
#endif
72
 
73
// ------------------------------------------------------------------------
74
 
75
int
76
set_mac_address( const char *interface, char *mac_address )
77
{
78
    int s, i;
79
    struct ifreq ifr;
80
 
81
    s = socket(AF_INET, SOCK_DGRAM, 0);
82
    if (s < 0) {
83
        perror("socket");
84
        return false;
85
    }
86
 
87
    diag_printf( "%s socket is %d:\n", interface, s );
88
 
89
    strcpy(ifr.ifr_name, interface);
90
 
91
    for ( i = 0; i < ETHER_ADDR_LEN; i++ )
92
        ifr.ifr_hwaddr.sa_data[i] = mac_address[i];
93
 
94
    diag_printf( "Mac addr %02x:%02x:%02x:%02x:%02x:%02x\n",
95
                 ifr.ifr_hwaddr.sa_data[0],
96
                 ifr.ifr_hwaddr.sa_data[1],
97
                 ifr.ifr_hwaddr.sa_data[2],
98
                 ifr.ifr_hwaddr.sa_data[3],
99
                 ifr.ifr_hwaddr.sa_data[4],
100
                 ifr.ifr_hwaddr.sa_data[5] );
101
 
102
    if (ioctl(s, SIOCSIFHWADDR, &ifr)) {
103
        perror("SIOCSIFHWADDR");
104
        close( s );
105
        return false;
106
    }
107
 
108
    diag_printf( "%s ioctl(SIOCSIFHWADDR) succeeded\n", interface );
109
 
110
    close( s );
111
 
112
    return true;
113
}
114
 
115
// ------------------------------------------------------------------------
116
void
117
net_test(cyg_addrword_t param)
118
{
119
    int results = 0;
120
    diag_printf("Start set_mac_address\n");
121
#ifdef CYGHWR_NET_DRIVER_ETH0
122
#ifdef DO_SET_ETH0
123
    diag_printf("Setting MAC of eth0 to %02x:%02x:%02x:%02x:%02x:%02x\n",
124
                new_eth0_addr[0],new_eth0_addr[1],
125
                new_eth0_addr[2],new_eth0_addr[3],
126
                new_eth0_addr[4],new_eth0_addr[5] );
127
    results += set_mac_address( "eth0", new_eth0_addr );
128
#endif
129
#endif
130
#ifdef CYGHWR_NET_DRIVER_ETH1
131
#ifdef DO_SET_ETH1
132
    diag_printf("Setting MAC of eth1 to %02x:%02x:%02x:%02x:%02x:%02x\n",
133
                new_eth1_addr[0],new_eth1_addr[1],
134
                new_eth1_addr[2],new_eth1_addr[3],
135
                new_eth1_addr[4],new_eth1_addr[5] );
136
    results += set_mac_address( "eth1", new_eth1_addr );
137
#endif
138
#endif
139
 
140
    if ( 0 == results )
141
        diag_printf( "**** Did not set any MAC addresses ****\n" );
142
 
143
    diag_printf("Init Network Interfaces\n");
144
    init_all_network_interfaces();
145
    diag_printf("After init.\n");
146
 
147
    cyg_test_exit();
148
}
149
 
150
// ------------------------------------------------------------------------
151
void
152
cyg_start(void)
153
{
154
    // Create a main thread, so we can run the scheduler and have time 'pass'
155
    cyg_thread_create(10,                // Priority - just a number
156
                      net_test,          // entry
157
                      0,                 // entry parameter
158
                      "Network test",    // Name
159
                     &thread_stack[0][0], // Stack
160
                      STACK_SIZE,        // Size
161
                      &thread_handle[0], // Handle
162
                      &thread_data[0]    // Thread data structure
163
            );
164
    cyg_thread_resume(thread_handle[0]);  // Start it
165
 
166
    cyg_scheduler_start();
167
}
168
 
169
// EOF set_mac_address.c

powered by: WebSVN 2.1.0

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