aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Foster <nick@ettus.com>2011-06-15 18:13:22 -0700
committerNick Foster <nick@ettus.com>2011-06-15 18:13:22 -0700
commit46fe7d86ee0425d9dc16f5a40c4d4bc061c43505 (patch)
tree36f8184963439c583c528ab931327a15d5cb0003
parent4b0c097cfa67560116ea5380b42c12c89d4d3d8f (diff)
downloaduhd-46fe7d86ee0425d9dc16f5a40c4d4bc061c43505.tar.gz
uhd-46fe7d86ee0425d9dc16f5a40c4d4bc061c43505.tar.bz2
uhd-46fe7d86ee0425d9dc16f5a40c4d4bc061c43505.zip
fw_updater: add broadcast addr finding for *nix/Win
-rwxr-xr-xhost/utils/usrp_n2xx_net_burner.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/host/utils/usrp_n2xx_net_burner.py b/host/utils/usrp_n2xx_net_burner.py
index 1fe62671c..65ddfa4e7 100755
--- a/host/utils/usrp_n2xx_net_burner.py
+++ b/host/utils/usrp_n2xx_net_burner.py
@@ -26,6 +26,8 @@ import struct
import socket
import sys
import time
+import platform
+import subprocess
########################################################################
# constants
@@ -121,6 +123,74 @@ def is_valid_fpga_image(fpga_image):
def is_valid_fw_image(fw_image):
return fw_image[:4] == bytes(b'\x0B\x0B\x0B\x0B')
+
+########################################################################
+# interface discovery and device enumeration
+########################################################################
+def get_interfaces():
+ if(platform.system() is "Windows"): return win_get_interfaces()
+ else: return unix_get_interfaces()
+
+def unix_get_interfaces():
+ ifconfig = subprocess.check_output("/sbin/ifconfig")
+ ip_addr_re = "cast\D*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
+ bcasts = re.findall(ip_addr_re, ifconfig)
+ return bcasts
+
+def win_get_interfaces():
+ from ctypes import Structure, windll, sizeof
+ from ctypes import POINTER, byref
+ from ctypes import c_ulong, c_uint, c_ubyte, c_char
+ MAX_ADAPTER_DESCRIPTION_LENGTH = 128
+ MAX_ADAPTER_NAME_LENGTH = 256
+ MAX_ADAPTER_ADDRESS_LENGTH = 8
+ class IP_ADDR_STRING(Structure):
+ pass
+ LP_IP_ADDR_STRING = POINTER(IP_ADDR_STRING)
+ IP_ADDR_STRING._fields_ = [
+ ("next", LP_IP_ADDR_STRING),
+ ("ipAddress", c_char * 16),
+ ("ipMask", c_char * 16),
+ ("context", c_ulong)]
+ class IP_ADAPTER_INFO (Structure):
+ pass
+ LP_IP_ADAPTER_INFO = POINTER(IP_ADAPTER_INFO)
+ IP_ADAPTER_INFO._fields_ = [
+ ("next", LP_IP_ADAPTER_INFO),
+ ("comboIndex", c_ulong),
+ ("adapterName", c_char * (MAX_ADAPTER_NAME_LENGTH + 4)),
+ ("description", c_char * (MAX_ADAPTER_DESCRIPTION_LENGTH + 4)),
+ ("addressLength", c_uint),
+ ("address", c_ubyte * MAX_ADAPTER_ADDRESS_LENGTH),
+ ("index", c_ulong),
+ ("type", c_uint),
+ ("dhcpEnabled", c_uint),
+ ("currentIpAddress", LP_IP_ADDR_STRING),
+ ("ipAddressList", IP_ADDR_STRING),
+ ("gatewayList", IP_ADDR_STRING),
+ ("dhcpServer", IP_ADDR_STRING),
+ ("haveWins", c_uint),
+ ("primaryWinsServer", IP_ADDR_STRING),
+ ("secondaryWinsServer", IP_ADDR_STRING),
+ ("leaseObtained", c_ulong),
+ ("leaseExpires", c_ulong)]
+ GetAdaptersInfo = windll.iphlpapi.GetAdaptersInfo
+ GetAdaptersInfo.restype = c_ulong
+ GetAdaptersInfo.argtypes = [LP_IP_ADAPTER_INFO, POINTER(c_ulong)]
+ adapterList = (IP_ADAPTER_INFO * 10)()
+ buflen = c_ulong(sizeof(adapterList))
+ rc = GetAdaptersInfo(byref(adapterList[0]), byref(buflen))
+ if rc == 0:
+ for a in adapterList:
+ adNode = a.ipAddressList
+ while True:
+ ipAddr = adNode.ipAddress
+ if ipAddr:
+ yield ipAddr
+ adNode = adNode.next
+ if not adNode:
+ break
+
########################################################################
# Burner class, holds a socket and send/recv routines
########################################################################
@@ -130,6 +200,7 @@ class burner_socket(object):
self._sock.settimeout(UDP_TIMEOUT)
self._sock.connect((addr, UDP_FW_UPDATE_PORT))
self.set_callbacks(lambda *a: None, lambda *a: None)
+ get_interfaces()
self.init_update() #check that the device is there
self.get_hw_rev()