diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-30 13:32:52 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-30 13:32:52 +0000 |
commit | f94fa1e464c9e2a87274c991dc6461f7f4c956d8 (patch) | |
tree | 1b88020a0dece1ae509cf3fb219b7cce487dc198 /host/utils/usrp2_recovery.py | |
parent | 29e88b3478aad89ff76363029395200a8601e667 (diff) | |
parent | 281307833c8275031bd2469e6aef3f472490749a (diff) | |
download | uhd-f94fa1e464c9e2a87274c991dc6461f7f4c956d8.tar.gz uhd-f94fa1e464c9e2a87274c991dc6461f7f4c956d8.tar.bz2 uhd-f94fa1e464c9e2a87274c991dc6461f7f4c956d8.zip |
Merge branch 'master' of git@ettus.sourcerepo.com:ettus/uhd into usrp_e
Conflicts:
host/include/uhd/usrp/dboard_id.hpp
host/lib/usrp/usrp2/usrp2_impl.cpp
Diffstat (limited to 'host/utils/usrp2_recovery.py')
-rwxr-xr-x | host/utils/usrp2_recovery.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/host/utils/usrp2_recovery.py b/host/utils/usrp2_recovery.py new file mode 100755 index 000000000..5654e93d3 --- /dev/null +++ b/host/utils/usrp2_recovery.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright 2010 Ettus Research LLC +# +# 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/>. +# + +""" +The usrp2 recovery app: + +When the usrp2 has an unknown or bad ip address in its eeprom, +it may not be possible to communicate with the usrp2 over ip/udp. + +This app will send a raw ethernet packet to bypass the ip layer. +The packet will contain a known ip address to burn into eeprom. +Because the recovery packet is sent with a broadcast mac address, +only one usrp2 should be present on the interface upon execution. + +This app requires super-user privileges and only works on linux. +""" + +import socket +import struct +import optparse + +BCAST_MAC_ADDR = 'ff:ff:ff:ff:ff:ff' +RECOVERY_ETHERTYPE = 0xbeee +IP_RECOVERY_CODE = 'addr' + +def mac_addr_repr_to_binary_string(mac_addr): + return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) + +if __name__ == '__main__': + parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__) + parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') + parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') + (options, args) = parser.parse_args() + + #create the raw socket + print "Opening raw socket on interface:", options.ifc + soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) + soc.bind((options.ifc, RECOVERY_ETHERTYPE)) + + #create the recovery packet + print "Loading packet with ip address:", options.new_ip + packet = struct.pack( + '!6s6sH4s4s', + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + RECOVERY_ETHERTYPE, + IP_RECOVERY_CODE, + socket.inet_aton(options.new_ip), + ) + + print "Sending packet (%d bytes)"%len(packet) + soc.send(packet) + print "Done" |