[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7362 - in usrp2/trunk/host: apps lib
From: |
eb |
Subject: |
[Commit-gnuradio] r7362 - in usrp2/trunk/host: apps lib |
Date: |
Sat, 5 Jan 2008 15:31:57 -0700 (MST) |
Author: eb
Date: 2008-01-05 15:31:56 -0700 (Sat, 05 Jan 2008)
New Revision: 7362
Added:
usrp2/trunk/host/apps/u2_burn_mac_addr.cc
Modified:
usrp2/trunk/host/apps/
usrp2/trunk/host/apps/Makefile.am
usrp2/trunk/host/lib/usrp2_basic.cc
usrp2/trunk/host/lib/usrp2_basic.h
Log:
new: u2_burn_mac_addr
Property changes on: usrp2/trunk/host/apps
___________________________________________________________________
Name: svn:ignore
- *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
+ *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
u2_burn_mac_addr
Modified: usrp2/trunk/host/apps/Makefile.am
===================================================================
--- usrp2/trunk/host/apps/Makefile.am 2008-01-05 20:04:17 UTC (rev 7361)
+++ usrp2/trunk/host/apps/Makefile.am 2008-01-05 22:31:56 UTC (rev 7362)
@@ -25,11 +25,14 @@
find_usrps \
rx_samples \
tx_samples \
- gen_const
+ gen_const \
+ u2_burn_mac_addr
find_usrps_SOURCES = find_usrps.cc
rx_samples_SOURCES = rx_samples.cc
tx_samples_SOURCES = tx_samples.cc
gen_const_SOURCES = gen_const.cc
+u2_burn_mac_addr = u2_burn_mac_addr.cc
+
Added: usrp2/trunk/host/apps/u2_burn_mac_addr.cc
===================================================================
--- usrp2/trunk/host/apps/u2_burn_mac_addr.cc (rev 0)
+++ usrp2/trunk/host/apps/u2_burn_mac_addr.cc 2008-01-05 22:31:56 UTC (rev
7362)
@@ -0,0 +1,114 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "usrp2_basic.h"
+#include <iostream>
+#include <getopt.h>
+#include <string.h>
+#include <time.h>
+
+
+static void
+usage(const char *progname)
+{
+ fprintf(stderr, "usage: %s [-e ethN] [-m old_mac_addr] new_mac_addr\n",
+ progname);
+ fprintf(stderr, " old_mac_addr defaults to 00:50:c2:85:3f:ff\n");
+ fprintf(stderr, " new_mac_address must be HH:HH or HH:HH:HH:HH:HH:HH\n");
+}
+
+int
+main(int argc, char **argv)
+{
+ int ch;
+ const char *interface = "eth0";
+ char *old_mac_addr_str = "00:50:c2:85:3f:ff";
+ char *new_mac_addr_str = 0;
+ u2_mac_addr_t old_mac_addr;
+ u2_mac_addr_t new_mac_addr;
+
+ while ((ch = getopt(argc, argv, "he:m:")) != EOF){
+ switch (ch){
+ case 'e':
+ interface = optarg;
+ break;
+
+ case 'm':
+ old_mac_addr_str = optarg;
+ break;
+
+ case 'h':
+ default:
+ usage(argv[0]);
+ exit(1);
+ }
+ }
+
+ if (argc - optind != 1){
+ usage(argv[0]);
+ exit(1);
+ }
+
+ new_mac_addr_str = argv[optind];
+
+ if (!usrp2_basic::parse_mac_addr(old_mac_addr_str, &old_mac_addr)){
+ fprintf(stderr, "invalid mac address: %s\n", old_mac_addr_str);
+ exit(1);
+ }
+ if (!usrp2_basic::parse_mac_addr(new_mac_addr_str, &new_mac_addr)){
+ fprintf(stderr, "invalid mac address: %s\n", new_mac_addr_str);
+ exit(1);
+ }
+
+
+ usrp2_basic *u2 = new usrp2_basic();
+
+ if (!u2->open(interface)){
+ std::cerr << "couldn't open " << interface << std::endl;
+ return 0;
+ }
+
+ if (!u2->find_usrp_by_mac(old_mac_addr, 0)){
+ std::cerr << "No USRP2 with address "
+ << old_mac_addr << " found.\n";
+ return 1;
+ }
+
+ if (!u2->burn_mac_addr(old_mac_addr, new_mac_addr)){
+ std::cerr << "Failed to burn mac address\n";
+ return 1;
+ }
+
+ // wait 250 ms
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 250000000;
+ nanosleep(&ts, 0);
+
+ // Now see if we can find it using it's new address
+ if (!u2->find_usrp_by_mac(new_mac_addr, 0)){
+ std::cerr << "Failed to find USRP2 using new address "
+ << new_mac_addr << ".\n";
+ return 1;
+ }
+
+ return 0;
+}
Property changes on: usrp2/trunk/host/apps/u2_burn_mac_addr.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-01-05 20:04:17 UTC (rev 7361)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-01-05 22:31:56 UTC (rev 7362)
@@ -146,6 +146,24 @@
}
bool
+usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u)
+{
+ std::vector<op_id_reply_t> r = find_usrps();
+ for (unsigned i = 0; i < r.size(); i++){
+ if (r[i].addr == addr){
+ if (u)
+ *u = r[i];
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+// ------------------------------------------------------------------------
+
+bool
usrp2_basic::start_rx(const u2_mac_addr_t &which)
{
uint8_t pktbuf[MAX_PKTLEN];
@@ -285,8 +303,67 @@
}
+bool
+usrp2_basic::burn_mac_addr(const u2_mac_addr_t &which,
+ const u2_mac_addr_t &new_addr)
+{
+ uint8_t pktbuf[MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ struct command {
+ u2_eth_packet_t h;
+ op_burn_mac_addr_t op;
+ };
+
+ command *c = (command *) pktbuf;
+ c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
+ c->h.ehdr._pad = 0;
+ c->h.ehdr.dst = which;
+ memcpy(&c->h.ehdr.src, d_ethernet->mac(), 6);
+ u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
+ u2p_set_timestamp(&c->h.fixed, -1);
+
+ c->op.opcode = OP_BURN_MAC_ADDR;
+ c->op.len = sizeof(op_burn_mac_addr_t);
+ c->op.addr = new_addr;
+ int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) != len)
+ return false;
+
+ return true;
+}
+
+
// ------------------------------------------------------------------------
+bool
+usrp2_basic::parse_mac_addr(const std::string &s, u2_mac_addr_t *p)
+{
+ p->addr[0] = 0x00;
+ p->addr[1] = 0x50;
+ p->addr[2] = 0xC2;
+ p->addr[3] = 0x85;
+ p->addr[4] = 0x30;
+ p->addr[5] = 0x00;
+
+ int len = s.size();
+ switch (len){
+
+ case 5:
+ return sscanf(s.c_str(), "%hhx:%hhx", &p->addr[4], &p->addr[5]) == 2;
+
+ case 17:
+ return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+ &p->addr[0], &p->addr[1], &p->addr[2],
+ &p->addr[3], &p->addr[4], &p->addr[5]) == 6;
+ default:
+ return false;
+ }
+}
+
+
+// ------------------------------------------------------------------------
+
std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x)
{
os << x.addr;
@@ -313,3 +390,7 @@
return os;
}
+bool operator==(const u2_mac_addr_t &a, const u2_mac_addr_t &b)
+{
+ return memcmp(&a, &b, sizeof(u2_mac_addr_t)) == 0;
+}
Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h 2008-01-05 20:04:17 UTC (rev 7361)
+++ usrp2/trunk/host/lib/usrp2_basic.h 2008-01-05 22:31:56 UTC (rev 7362)
@@ -47,6 +47,21 @@
*/
std::vector<op_id_reply_t> find_usrps();
+ /*!
+ * \brief Find usrp by mac address
+ */
+ bool find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u);
+
+ /*!
+ * \brief Parse short or long format mac address.
+ * \param[in] s must be either HH:HH or HH:HH:HH:HH:HH:HH.
+ * \param[out] p receives the parsed address
+ *
+ * If \p s is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH
+ */
+ static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
+
+
bool start_rx(const u2_mac_addr_t &which);
bool stop_rx(const u2_mac_addr_t &which);
@@ -96,9 +111,15 @@
bool write_samples(const u2_mac_addr_t &which,
u2_eth_samples_t *pkt, size_t nsamples);
+
+ bool burn_mac_addr(const u2_mac_addr_t &which,
+ const u2_mac_addr_t &new_addr);
+
};
std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x);
std::ostream& operator<<(std::ostream &os, const u2_mac_addr_t &x);
+bool operator==(const u2_mac_addr_t &a, const u2_mac_addr_t &b);
+
#endif /* INCLUDED_USRP2_BASIC_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7362 - in usrp2/trunk/host: apps lib,
eb <=