Go to the documentation of this file.00001
00002
00003 import subprocess
00004 import re
00005 import sys
00006
00007 def get_hwsim_list():
00008 p = subprocess.Popen(["iwconfig"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00009 (out, err) = p.communicate()
00010
00011 iface_list = re.findall('(?m)^\S+', out)
00012 hwsim_list = []
00013 for iface in iface_list:
00014 f=open("/sys/class/net/" + iface + "/device/uevent")
00015 out = f.read()
00016 driver = re.findall('DRIVER.*(mac80211_hwsim)', out)
00017 if driver:
00018 hwsim_list.append(iface)
00019
00020 return hwsim_list
00021
00022 def reload_hwsim_module(radios):
00023 ret = subprocess.call(["rmmod", "mac80211_hwsim"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00024 ret = subprocess.call(["modprobe", "mac80211_hwsim", "radios=" + str(radios)])
00025 if ret != 0:
00026 raise OSError(ret, "could not load mac80211_hwsim module")
00027
00028 if __name__ == "__main__":
00029 if len(sys.argv) < 3:
00030 print "Usage: find_hwsim_iface.py <radio_index> <total_radios>"
00031 print "Example: find_hwsim_iface.py 1 2"
00032 sys.exit(1)
00033
00034 curr_radio = int(sys.argv[1])
00035 total_radios = int(sys.argv[2])
00036
00037 hwsim_list = get_hwsim_list()
00038
00039 if len(hwsim_list) < total_radios:
00040 reload_hwsim_module(total_radios)
00041
00042 hwsim_list = get_hwsim_list()
00043
00044 if len(hwsim_list) < total_radios:
00045 raise OSError(-1, "could only spawn " + str(len(hwsim_list)) +
00046 " radios instead of " + str(total_radios))
00047
00048 if curr_radio < 1 or curr_radio > len(hwsim_list):
00049 raise IOError(-1, "radio index %d not available (total available radios = %d)"
00050 %(curr_radio, total_radios))
00051
00052 sys.stdout.write(hwsim_list[curr_radio - 1])
00053
00054