3 * Copyright 2007,2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <usrp2/usrp2.h>
32 static volatile bool signaled = false;
41 install_sig_handler(int signum,
42 void (*new_handler)(int))
44 struct sigaction new_action;
45 memset (&new_action, 0, sizeof (new_action));
47 new_action.sa_handler = new_handler;
48 sigemptyset (&new_action.sa_mask);
49 new_action.sa_flags = 0;
51 if (sigaction (signum, &new_action, 0) < 0){
52 perror ("sigaction (install new)");
53 throw std::runtime_error ("sigaction");
59 usage(const char *progname)
61 fprintf(stderr, "usage: %s [-e ethN] [-m old_mac_addr] new_mac_addr\n",
63 fprintf(stderr, " old_mac_addr defaults to 00:50:c2:85:3f:ff\n");
64 fprintf(stderr, " new_mac_address must be HH:HH or HH:HH:HH:HH:HH:HH\n");
68 check_mac_addr_syntax(const std::string &s)
70 unsigned char addr[6];
72 addr[0] = 0x00; // Matt's IAB
84 return sscanf(s.c_str(), "%hhx:%hhx", &addr[4], &addr[5]) == 2;
87 return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
88 &addr[0], &addr[1], &addr[2],
89 &addr[3], &addr[4], &addr[5]) == 6;
99 main(int argc, char **argv)
102 const char *interface = "eth0";
103 const char *old_mac_addr = "00:50:c2:85:3f:ff";
104 const char *new_mac_addr = 0;
106 while ((ch = getopt(argc, argv, "he:m:")) != EOF){
113 old_mac_addr = optarg;
123 if (argc - optind != 1){
128 new_mac_addr = argv[optind];
130 if (!check_mac_addr_syntax(old_mac_addr)){
131 fprintf(stderr, "invalid mac address: %s\n", old_mac_addr);
134 if (!check_mac_addr_syntax(new_mac_addr)){
135 fprintf(stderr, "invalid mac address: %s\n", new_mac_addr);
139 install_sig_handler(SIGINT, sig_handler);
141 usrp2::usrp2::sptr u2;
144 u2 = usrp2::usrp2::make(interface, old_mac_addr);
146 catch (std::exception const &e){
147 std::cerr << e.what() << std::endl;
151 if (!u2->burn_mac_addr(new_mac_addr)){
152 std::cerr << "Failed to burn mac address: "
153 << new_mac_addr << std::endl;
162 ts.tv_nsec = 250000000;
166 u2 = usrp2::usrp2::make(interface, new_mac_addr);
168 catch (std::exception const &e){
169 std::cerr << "Failed to connect to USRP2 using new addr: "
170 << new_mac_addr << std::endl;
171 std::cerr << e.what() << std::endl;