1 //==========================================================================
3 // tests/set_mac_address.c
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.
8 //==========================================================================
9 //####BSDCOPYRIGHTBEGIN####
11 // -------------------------------------------
13 // Portions of this software may have been derived from OpenBSD or other sources,
14 // and are covered by the appropriate copyright disclaimers included herein.
16 // -------------------------------------------
18 //####BSDCOPYRIGHTEND####
19 //==========================================================================
20 //#####DESCRIPTIONBEGIN####
29 //####DESCRIPTIONEND####
31 //==========================================================================
33 #include <pkgconf/system.h>
34 #ifdef CYGBLD_DEVS_ETH_DEVICE_H // Get the device config if it exists
35 #include CYGBLD_DEVS_ETH_DEVICE_H
39 // SET_MAC_ADDRESS test code
43 #include <netinet/if_ether.h>
46 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
47 static char thread_stack[NUMTHREADS][STACK_SIZE];
48 static cyg_thread thread_data[NUMTHREADS];
49 static cyg_handle_t thread_handle[NUMTHREADS];
61 // ------------------------------------------------------------------------
62 // remove NT to make this utility be useful ;-)
66 // These are commented out to make sure you choose a value:
68 //static cyg_uint8 new_eth0_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdd};
69 //static cyg_uint8 new_eth0_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdb};
72 //static cyg_uint8 new_eth1_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xde};
73 //static cyg_uint8 new_eth1_addr[6]={ 0x0,0x90,0x27,0x8c,0x57,0xdc};
76 // ------------------------------------------------------------------------
79 set_mac_address( const char *interface, char *mac_address )
84 s = socket(AF_INET, SOCK_DGRAM, 0);
90 diag_printf( "%s socket is %d:\n", interface, s );
92 strcpy(ifr.ifr_name, interface);
94 for ( i = 0; i < ETHER_ADDR_LEN; i++ )
95 ifr.ifr_hwaddr.sa_data[i] = mac_address[i];
97 diag_printf( "Mac addr %02x:%02x:%02x:%02x:%02x:%02x\n",
98 ifr.ifr_hwaddr.sa_data[0],
99 ifr.ifr_hwaddr.sa_data[1],
100 ifr.ifr_hwaddr.sa_data[2],
101 ifr.ifr_hwaddr.sa_data[3],
102 ifr.ifr_hwaddr.sa_data[4],
103 ifr.ifr_hwaddr.sa_data[5] );
105 if (ioctl(s, SIOCSIFHWADDR, &ifr)) {
106 perror("SIOCSIFHWADDR");
111 diag_printf( "%s ioctl(SIOCSIFHWADDR) succeeded\n", interface );
118 // ------------------------------------------------------------------------
120 net_test(cyg_addrword_t param)
123 diag_printf("Start set_mac_address\n");
124 #ifdef CYGHWR_NET_DRIVER_ETH0
126 diag_printf("Setting MAC of eth0 to %02x:%02x:%02x:%02x:%02x:%02x\n",
127 new_eth0_addr[0],new_eth0_addr[1],
128 new_eth0_addr[2],new_eth0_addr[3],
129 new_eth0_addr[4],new_eth0_addr[5] );
130 results += set_mac_address( "eth0", new_eth0_addr );
133 #ifdef CYGHWR_NET_DRIVER_ETH1
135 diag_printf("Setting MAC of eth1 to %02x:%02x:%02x:%02x:%02x:%02x\n",
136 new_eth1_addr[0],new_eth1_addr[1],
137 new_eth1_addr[2],new_eth1_addr[3],
138 new_eth1_addr[4],new_eth1_addr[5] );
139 results += set_mac_address( "eth1", new_eth1_addr );
144 diag_printf( "**** Did not set any MAC addresses ****\n" );
146 diag_printf("Init Network Interfaces\n");
147 init_all_network_interfaces();
148 diag_printf("After init.\n");
153 // ------------------------------------------------------------------------
157 // Create a main thread, so we can run the scheduler and have time 'pass'
158 cyg_thread_create(10, // Priority - just a number
160 0, // entry parameter
161 "Network test", // Name
162 &thread_stack[0][0], // Stack
164 &thread_handle[0], // Handle
165 &thread_data[0] // Thread data structure
167 cyg_thread_resume(thread_handle[0]); // Start it
169 cyg_scheduler_start();
172 // EOF set_mac_address.c