root / host / utils / usrp2_recovery.py @ 3e4f6418
History | View | Annotate | Download (2.41 KB)
| 1 | 6458eca9 | Josh Blum | #!/usr/bin/env python
|
|---|---|---|---|
| 2 | d1e67602 | Josh Blum | #
|
| 3 | 07222254 | Josh Blum | # Copyright 2010-2011 Ettus Research LLC
|
| 4 | d1e67602 | Josh Blum | #
|
| 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.
|
||
| 9 | #
|
||
| 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.
|
||
| 14 | #
|
||
| 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/>.
|
||
| 17 | #
|
||
| 18 | 6458eca9 | Josh Blum | |
| 19 | """
|
||
| 20 | The usrp2 recovery app:
|
||
| 21 |
|
||
| 22 | When the usrp2 has an unknown or bad ip address in its eeprom,
|
||
| 23 | it may not be possible to communicate with the usrp2 over ip/udp.
|
||
| 24 |
|
||
| 25 | This app will send a raw ethernet packet to bypass the ip layer.
|
||
| 26 | The packet will contain a known ip address to burn into eeprom.
|
||
| 27 | Because the recovery packet is sent with a broadcast mac address,
|
||
| 28 | only one usrp2 should be present on the interface upon execution.
|
||
| 29 |
|
||
| 30 | This app requires super-user privileges and only works on linux.
|
||
| 31 | """
|
||
| 32 | |||
| 33 | import socket |
||
| 34 | import struct |
||
| 35 | import optparse |
||
| 36 | |||
| 37 | BCAST_MAC_ADDR = 'ff:ff:ff:ff:ff:ff'
|
||
| 38 | RECOVERY_ETHERTYPE = 0xbeee
|
||
| 39 | IP_RECOVERY_CODE = 'addr'
|
||
| 40 | |||
| 41 | def mac_addr_repr_to_binary_string(mac_addr): |
||
| 42 | 07222254 | Josh Blum | return ''.join([chr(int(x, 16)) for x in mac_addr.split(':')]) |
| 43 | 6458eca9 | Josh Blum | |
| 44 | if __name__ == '__main__': |
||
| 45 | 12ca1b61 | Josh Blum | parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__)
|
| 46 | 6458eca9 | Josh Blum | parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') |
| 47 | parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') |
||
| 48 | (options, args) = parser.parse_args() |
||
| 49 | |||
| 50 | #create the raw socket
|
||
| 51 | 07222254 | Josh Blum | print("Opening raw socket on interface:", options.ifc)
|
| 52 | 6458eca9 | Josh Blum | soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) |
| 53 | soc.bind((options.ifc, RECOVERY_ETHERTYPE)) |
||
| 54 | |||
| 55 | #create the recovery packet
|
||
| 56 | 07222254 | Josh Blum | print("Loading packet with ip address:", options.new_ip)
|
| 57 | 6458eca9 | Josh Blum | packet = struct.pack( |
| 58 | '!6s6sH4s4s',
|
||
| 59 | mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), |
||
| 60 | mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), |
||
| 61 | RECOVERY_ETHERTYPE, |
||
| 62 | IP_RECOVERY_CODE, |
||
| 63 | socket.inet_aton(options.new_ip), |
||
| 64 | ) |
||
| 65 | 12ca1b61 | Josh Blum | |
| 66 | 07222254 | Josh Blum | print("Sending packet (%d bytes)"%len(packet)) |
| 67 | 6458eca9 | Josh Blum | soc.send(packet) |
| 68 | 07222254 | Josh Blum | print("Done") |