Commit 4849bab4c9e07290201a974a7decc2cbd454dd16

Authored by Ginés García
0 parents

First commit

README.md 0 → 100644
  1 +++ a/README.md
... ...
setup-wlan.py 0 → 100644
  1 +++ a/setup-wlan.py
... ... @@ -0,0 +1,73 @@
  1 +import sys, os.path, threading, time
  2 +
  3 +# It Includes search_ap_data & configure_ap
  4 +import utils_ap
  5 +import utils_config
  6 +import utils_peers
  7 +
  8 +# Global Variables
  9 +threads = []
  10 +
  11 +utils_config.check_input_param(str(sys.argv[1]), str(sys.argv[2]), len(sys.argv))
  12 +
  13 +config_file_path = str(sys.argv[1])
  14 +peers_file_path = str(sys.argv[2])
  15 +
  16 +# Get all the information from json
  17 +ap_addr, bssid, rate, mac_ap, power, channel, video_nodes, data_nodes, mechanism = utils_config.get_config_from_json(config_file_path)
  18 +# Remove M from rate (Ej: 24M -> 24)
  19 +rate = rate[:-1]
  20 +
  21 +# Check selected mechanism and get extra data if needed
  22 +if utils_config.check_mechanism(mechanism) == "not_valid":
  23 + print "Mechanism not supported"
  24 + sys.exit()
  25 +elif mechanism == "UR":
  26 + retries = utils_config.get_specific_config(config_file_path,mechanism)
  27 +elif mechanism == "BLOCK_ACK":
  28 + b_size = utils_config.get_specific_config(config_file_path,mechanism)
  29 +
  30 +# Setting up AP and peers
  31 +if video_nodes > 0:
  32 +
  33 + # AP configuration
  34 + wlan0_ip, mac, wired_ip = utils_ap.search_ap_data(peers_file_path, ap_addr)
  35 + if (wlan0_ip == "EMPTY") or (mac == "EMPTY") or (wired_ip == "EMPTY"):
  36 + print "No configuration for the AP available on peers file."
  37 + sys.exit()
  38 + else:
  39 + utils_ap.reload_ap(ap_addr)
  40 + utils_ap.set_mechanism(ap_addr, mechanism)
  41 + utils_ap.start_ap(ap_addr, wlan0_ip, rate, channel, power)
  42 +
  43 + # Check ap configuration
  44 + ap_status = utils_ap.check_ap(ap_addr, wlan0_ip)
  45 + if ap_status != "ok":
  46 + print "AP not configured correctly. Problems with %s" % ap_status
  47 + sys.exit()
  48 + else:
  49 + print "AP configured"
  50 +
  51 + # Peers Configuration
  52 + #utils_peers.configure_peers(peers_file_path, ap_addr, bssid, rate, power, channel, mechanism)
  53 +'''
  54 + index = 0
  55 + with open(peers_file_path) as peers_file_opened:
  56 + for peer in peers_file_opened:
  57 + peer = peer.split()
  58 + peer_ip = peer[0]
  59 + peer_mac = peer[1]
  60 + peer_ip_wired = peer[2]
  61 +
  62 + if peer_ip_wired != ap_addr:
  63 + index = index+1
  64 + thr_name = "thread_%d" % index
  65 + t = threading.Thread(target=utils_peers.configure_peer, name=thr_name, args=(peer_ip, peer_ip_wired, bssid, rate, power, channel, mechanism))
  66 + threads.append(t)
  67 + t.start()
  68 + time.sleep(0.005)
  69 +
  70 + for thread in threads:
  71 + t.join()
  72 + print "Configuration process end"
  73 +'''
... ...
utils_ap.py 0 → 100644
  1 +++ a/utils_ap.py
... ... @@ -0,0 +1,149 @@
  1 +import os
  2 +import utils_config ## incluse ssh command execution method
  3 +
  4 +# Global variables
  5 +path_module_b43 = "/lib/modules/2.6.36/kernel/drivers/net/wireless"
  6 +path_module_80211 = "/lib/modules/2.6.36/kernel/net/mac80211"
  7 +path_firm_b43_blockack = /lib/firmware/b43.video/firmware.blockack
  8 +
  9 +# Get ap data from peers file
  10 +# - Input: Path to peers file and wired ip where AP is located
  11 +# - Output: peer[0] (wlan0 ip - 192.168.98.1), peer[1] (mac address), peer[2] (wired ip - 192.168.97.1)
  12 +def search_ap_data(peers_file, ap_addr):
  13 + with open(peers_file) as peers_file_opened:
  14 + for peer in peers_file_opened:
  15 + if ap_addr in peer:
  16 + peer = peer.split()
  17 + return peer[0], peer[1], peer[2]
  18 +
  19 + return "EMPTY", "EMPTY", "EMPTY"
  20 +
  21 +
  22 +# Reload all the modules needed by the ap
  23 +# - Input: ap_addr
  24 +def reload_ap(ap_addr):
  25 + print "Reload AP modules using wired ip -> %s" % ap_addr
  26 +
  27 + hostapd_pids = utils_config.exec_command_ssh(ap_addr, "pgrep -x hostapd")
  28 + if hostapd_pids != "ERROR":
  29 + for pid in hostapd_pids:
  30 + pid = int(pid)
  31 + utils_config.exec_command_ssh(ap_addr, ("kill -SIGTERM %d" % pid))
  32 + print "Process hostapd (pid = %d) killed" % pid
  33 +
  34 + print "Reconfiguring Interface ..."
  35 + utils_config.exec_command_ssh(ap_addr, "rmmod ath9k && sleep 0.5")
  36 + utils_config.exec_command_ssh(ap_addr, "rmmod mac80211")
  37 + utils_config.exec_command_ssh(ap_addr, "rmmod b43")
  38 +
  39 + utils_config.exec_command_ssh(ap_addr, "rm /lib/firmware/b43")
  40 + utils_config.exec_command_ssh(ap_addr, ("rm %s/b43/b43.ko" % path_module_b43))
  41 + utils_config.exec_command_ssh(ap_addr, ("rm %s/b43" % path_module_b43))
  42 + utils_config.exec_command_ssh(ap_addr, ("rm %s/mac80211.ko" % path_module_80211))
  43 +
  44 + utils_config.exec_command_ssh(ap_addr, ("ln -s %s/mac80211.video.ko %s/mac80211.ko" % (path_module_80211, path_module_80211)))
  45 + utils_config.exec_command_ssh(ap_addr, "modprobe mac80211")
  46 + utils_config.exec_command_ssh(ap_addr, ("ln -s %s/b43.video %s/b43" % (path_module_b43, path_module_b43)))
  47 +
  48 +# Enable the required modules according to the selected mechanism
  49 +# - Input: AP address, mechanism and rate. In addition b_size or retries if mechanism is BLOCK_ACK or UR
  50 +def set_mechanism(ap_addr, mechanism, rate, b_size):
  51 + print "Mechanism %s selected for the AP. Loading modules ..." % mechanism
  52 +
  53 + if mechanism == "BLOCK_ACK":
  54 + set_block_ack(rate, b_size)
  55 + elif mechanism == "DMS":
  56 + set_dms()
  57 + elif mechanism == "UR":
  58 + set_ur(ap_addr, rate, retries)
  59 + elif mechanism == "LEGACY"
  60 +
  61 +
  62 +# Check if all the configuration is correctly set
  63 +# - Input: AP address
  64 +def check_ap(ap_addr, wlan0_ip):
  65 + print "Checking AP ..."
  66 + if utils_config.exec_command_ssh(ap_addr, "pgrep -x hostapd") == "ERROR":
  67 + return "hostapd"
  68 + elif utils_config.exec_command_ssh(ap_addr, "modprobe -l | grep mac80211.ko") == "ERROR":
  69 + return "mac80211"
  70 + elif utils_config.exec_command_ssh(ap_addr, "modprobe -l | grep b43.ko") == "ERROR":
  71 + return "b43"
  72 + else:
  73 + ap_status = utils_config.check_ping(wlan0_ip)
  74 + if ap_status != "ok":
  75 + return "ERROR"
  76 + else:
  77 + return "ok"
  78 +
  79 +# Load modules in order to enable BLOCK_ACK mechanism
  80 +# - Input: AP wired address, rate and b_size
  81 +def set_block_ack(ap_addr, rate, b_size):
  82 + utils_config.exec_command("cp %s/%s/ucode5.back-%s.fw %s/ucode5.fw" % (path_firm_b43_blockack, rate, b_size, path_firm_b43_blockack))
  83 + # DMA
  84 + #utils_config.exec_command_ssh(ap_addr, ("cp %s/%s/ucode5.back-%s.fw.dma %s/ucode5.fw" % (path_firm_b43_blockack, rate, b_size, path_firm_b43_blockack)))
  85 + utils_config.exec_command_ssh(ap_addr, "cp %s/%s/ucode5.back-%s.fw %s/ucode5.fw" % path_firm_b43_blockack, rate, b_size path_firm_b43_blockack))
  86 + # END DMA
  87 +
  88 + utils_config.exec_command_ssh(ap_addr, "ln -s %s /lib/firmware/b43" % path_firm_b43_blockack)
  89 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.rate-adaptation.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  90 + #utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.blockack.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  91 +#PABLO
  92 +# ATTENTION: frate=1 implies the transmission rate is fixed, so no rate controller
  93 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=1 aseq=1 frate=0 bsize=%s brate=%s && sleep 0.5" % (b_size, rate))
  94 +
  95 +
  96 +# Load modules in order to enable DMS mechanism
  97 +# - Input: AP wired address and rate
  98 +def set_dms(ap_addr, rate):
  99 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.dms /lib/firmware/b43")
  100 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.dms.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  101 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=0 brate=%s && sleep 0.5" % rate)
  102 +
  103 +
  104 +# Load modules in order to enable UR mechanism
  105 +# - Input: AP wired address, rate and retries
  106 +def set_ur(ap_addr, rate, retries):
  107 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.ur /lib/firmware/b43")
  108 + utils_config.exec_command_ssh(ap_addr, "rm /lib/firmware/b43.video/firmware.ur/ucode5.fw")
  109 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.ur/ucode5.ur-%s.fw /lib/firmware/b43/ucode5.fw" % retries)
  110 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.ur.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  111 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=1 brate=rate && sleep 0.5" % rate)
  112 +
  113 +
  114 +# Load modules in order to enable LEGACY mechanism
  115 +# - Input: AP wired address and rate
  116 +def set_legacy(ap_addr, rate):
  117 + utils_config.exec_command_ssh(ap_addr, "ln -s /lib/firmware/b43.video/firmware.dms /lib/firmware/b43")
  118 + utils_config.exec_command_ssh(ap_addr, "ln -s %s/b43/b43.dms.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  119 + utils_config.exec_command_ssh(ap_addr, "modprobe b43 qos=0 brate=%s && sleep 0.5" % rate)
  120 +
  121 +# Starts AP with the given configuration and set up wlan0
  122 +# - Input: Input: AP address, rate, channel and power that we want to stablish in the AP
  123 +def start_ap(ap_addr, wlan0_ip, rate, channel, power):
  124 + print "Starting AP on %s with rate = %s, power = %s " % (wlan0_ip, rate, power)
  125 + utils_config.exec_command_ssh(ap_addr, "ifconfig wlan0 %s up" % wlan0_ip)
  126 + utils_config.exec_command_ssh(ap_addr, "iw reg set JP")
  127 +
  128 + #print "Running hostapd and setting his configuration and log file"
  129 + utils_config.exec_command_ssh(ap_addr, ("cp $PWD/hostapd-minimal-R %s-%s.conf $PWD/hostapd-minimal.conf" % (rate, channel)))
  130 + utils_config.exec_command_ssh(ap_addr, "$PWD/hostapd -ddd $PWD/hostapd-minimal.conf > $PWD/hostap.log &")
  131 + # utils_config.exec_command_ssh(ap_addr, "hostapd -B /root/hostapd-minimal.conf")
  132 +
  133 + #print "Configuring Rate and TX Power"
  134 + utils_config.exec_command_ssh(ap_addr, ("iwconfig wlan0 rate %s fixed txpower %s fixed" % (rate, power)))
  135 +
  136 + #print "Configuring multicast route"
  137 + utils_config.exec_command_ssh(ap_addr, "route add -host 224.0.0.1 wlan0")
  138 +
  139 + #print "Setting arp table"
  140 + #utils_config.exec_command_ssh(ap_addr, "$PWD/setarp.sh $PATH_AP")
  141 +
  142 +
  143 +
  144 +
  145 +
  146 +
  147 +
  148 +
  149 +
... ...
utils_ap.pyc 0 → 100644
No preview for this file type
utils_config.py 0 → 100644
  1 +++ a/utils_config.py
... ... @@ -0,0 +1,102 @@
  1 +import sys, os, subprocess
  2 +import json
  3 +
  4 +
  5 +def check_input_param(config_file_path, peers_file_path, args_len):
  6 + # Check path to config file and peers file
  7 + if (args_len != 3):
  8 + print "Usage: ./setup-wlan.sh route_to_config_file.json route_to_peers_file"
  9 + sys.exit()
  10 + # Check path to config file and peers file
  11 + if (not os.path.isfile(config_file_path)):
  12 + print "Configuration file missing."
  13 + sys.exit()
  14 + elif (not os.path.isfile(peers_file_path)):
  15 + print "Peers file missing."
  16 + sys.exit()
  17 +
  18 +
  19 +# Get data from json file
  20 +# - Input: path where config file will be located
  21 +# - Output: Parsed information
  22 +def get_config_from_json(config_file_path):
  23 + with open(config_file_path) as json_data:
  24 + data = json.load(json_data)
  25 +
  26 + return data["apaddress"], data["bssid"], data['rate'], "EMPTY", int(data['txpower']), int(data['channel']), int(data['videonodes']), int(data['datanodes']), data['mechanism']
  27 +
  28 +
  29 +# Get specific values for UR and BLOCK_ACK mechanisms
  30 +# -Input: mechanism
  31 +# -Output: retrieved value based on the mechanism
  32 +def get_specific_config(config_file_path,mechanism):
  33 + with open(config_file_path) as json_data:
  34 + data = json.load(json_data)
  35 + if mechanism == "UR":
  36 + return data["retries"]
  37 + elif mechanism == "BLOCK_ACK":
  38 + return data["b_size"]
  39 +
  40 +# Executes a command in a remote host
  41 +# - Input: host ip, command to be executed
  42 +# - Output: stdout or ERROR
  43 +def exec_command(command):
  44 + p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
  45 + (output, err) = p.communicate()
  46 + if err:
  47 + print "Error: command %s" % command
  48 +
  49 +# Executes a command in a remote host
  50 +# - Input: host ip, command to be executed
  51 +# - Output: stdout or ERROR
  52 +def exec_command_ssh(host, command):
  53 + #print command
  54 + ssh = subprocess.Popen(["ssh", "%s" % host, command],
  55 + shell=False,
  56 + stdout=subprocess.PIPE,
  57 + stderr=subprocess.PIPE)
  58 + result = ssh.stdout.readlines()
  59 + if result == []:
  60 + return "ERROR"
  61 + else:
  62 + return result
  63 +
  64 +# Check if host is reachable
  65 +# - Input: host ip
  66 +# - Output: ok if host is reachable, ping_error in other cases
  67 +def check_ping(host):
  68 + with open(os.devnull, "wb") as limbo:
  69 + result = subprocess.Popen(["ping", "-c", "1", "-n", host],stdout=limbo, stderr=limbo).wait()
  70 + if result:
  71 + return "ping_error"
  72 + else:
  73 + return "ok"
  74 +
  75 +def check_mechanism(mechanism):
  76 + if (mechanism != "UR") and (mechanism != "DMS") and (mechanism != "BLOCK_ACK") and (mechanism != "LEGACY"):
  77 + return "not_valid"
  78 + else:
  79 + return "valid"
  80 +
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
  87 +
  88 +
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +
  96 +
  97 +
  98 +
  99 +
  100 +
  101 +
  102 +
... ...
utils_config.pyc 0 → 100644
No preview for this file type
utils_peers.py 0 → 100644
  1 +++ a/utils_peers.py
... ... @@ -0,0 +1,92 @@
  1 +import threading
  2 +import utils_config
  3 +import os, sys, time, re, subprocess
  4 +
  5 +# Global variables
  6 +path_module_b43 = "/lib/modules/2.6.36/kernel/drivers/net/wireless"
  7 +path_module_80211 = "/lib/modules/2.6.36/kernel/net/mac80211"
  8 +
  9 +# Run method executed by threads in order to configure one peer
  10 +# - Input: peer_ip, peer_ip_wired, bssid, rate, power, channel
  11 +# - Configure interfaces, load modules based on the selected mechanism, start peer and check it's configuration
  12 +def configure_peer(peer_ip, peer_ip_wired, bssid, rate, power, channel, mechanism):
  13 + print threading.currentThread().getName(), "configuring %s" % peer_ip_wired
  14 + reload_peer(peer_ip_wired)
  15 + set_mechanism(peer_ip_wired, mechanism)
  16 + start_ap(peer_ip_wired, peer_ip, bssid, rate, power, channel)
  17 +
  18 + peer_status = check_peer(peer_ip_wired, peer_ip)
  19 + if peer_status != "ok":
  20 + print threading.currentThread().getName(), "Peer (wired)%s not configured correctly. Problems with %s" % (peer_ip_wired, peer_status)
  21 + sys.exit()
  22 + else:
  23 + print "Peer configured - wired = %s, wlan0 = %s" % (peer_ip_wired, peer_ip)
  24 +
  25 +
  26 +# Reconfigure peer interface and enable mac80211 module
  27 +# - Input: peer ip wired
  28 +def reload_peer(peer_ip_wired):
  29 +
  30 + # kill all wpa supplicants
  31 + wpa_supplicant_pids = utils_config.exec_command_ssh(peer_ip_wired, "pgrep -x wpa_supplicant")
  32 + for pid in wpa_supplicant_pids:
  33 + pid = int(pid)
  34 + utils_config.exec_command_ssh(peer_ip_wired, ("kill -SIGTERM %d" % pid))
  35 + #print "Process wpa supplicand (pid = %d) killed" % pid
  36 +
  37 + # Reconfigure interface
  38 + #print "Reconfiguring peer %s Interface" % peer_ip_wired
  39 + utils_config.exec_command_ssh(peer_ip_wired, "rmmod b43 && sleep 1")
  40 + utils_config.exec_command_ssh(peer_ip_wired, "rmmod mac80211")
  41 + utils_config.exec_command_ssh(peer_ip_wired, "rm /lib/firmware/b43")
  42 + utils_config.exec_command_ssh(peer_ip_wired, "rm %s/b43/b43.ko" % path_module_b43)
  43 + utils_config.exec_command_ssh(peer_ip_wired, "rm %s/b43" % path_module_b43)
  44 + utils_config.exec_command_ssh(peer_ip_wired, "rm %s/mac80211.ko" % path_module_80211)
  45 + utils_config.exec_command_ssh(peer_ip_wired, "ln -s %s/mac80211.video.ko %s/mac80211.ko" % (path_module_80211, path_module_80211))
  46 + utils_config.exec_command_ssh(peer_ip_wired, "ln -s %s/b43.orig %s/b43" % (path_module_b43,path_module_b43))
  47 + utils_config.exec_command_ssh(peer_ip_wired, "modprobe mac80211")
  48 +
  49 +
  50 +# Enable b43 module using different sources depending of the selected mechanism
  51 +# - Input: Peer address, mechanism
  52 +def set_mechanism(peer_ip_wired, mechanism):
  53 + #print "Mechanism %s selected for the peer" % mechanism
  54 +
  55 + if mechanism == "LEGACY":
  56 + utils_config.exec_command_ssh(peer_ip_wired, "ln -s /lib/firmware/b43.legacy/ /lib/firmware/b43")
  57 + #utils_config.exec_command_ssh(peer_ip_wired, "ln -s %s/b43/b43-2.6.36-orig.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  58 + utils_config.exec_command_ssh(peer_ip_wired, "ln -s %s/b43/b43.orig-dmasingleworker.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  59 + utils_config.exec_command_ssh(peer_ip_wired, "modprobe b43 qos=1 && sleep 1")
  60 +
  61 +
  62 +# Start peer with the given configuration, set up wlan0 (peer_ip -> 192.168.98.xxx) and join to the AP
  63 +# - Input: Input: Peer address, rate, channel and power that we want to stablish in the AP
  64 +def start_ap(peer_ip_wired, peer_ip, bssid, rate, power, channel):
  65 + # Up wlan0 ,search and join AP
  66 + utils_config.exec_command_ssh(peer_ip_wired, "ifconfig wlan0 %s up" % peer_ip)
  67 + utils_config.exec_command_ssh(peer_ip_wired, "iwlist wlan0 scan | grep %s -C 5" % bssid)
  68 + utils_config.exec_command_ssh(peer_ip_wired, "wpa_supplicant -B -Dwext -iwlan0 -c/root/wpa_supplicant.conf")
  69 + utils_config.exec_command_ssh(peer_ip_wired, "iwconfig wlan0 rate %s fixed channel %s txpower %s fixed" % (rate, channel, power))
  70 +
  71 + #print "Configuring multicast route"
  72 + #utils_config.exec_command_ssh(peer_ip_wired, "route add -host 224.0.0.1 wlan0")
  73 +
  74 + #print "Setting arp table"
  75 + #utils_config.exec_command_ssh(peer_ip_wired, "/root/setarp.sh 192.168.98.10")
  76 +
  77 +# Check if all the configuration is correctly set
  78 +# - Input: Peer address (wired and wlan0 interface)
  79 +def check_peer(peer_ip_wired, peer_ip):
  80 + if utils_config.exec_command_ssh(peer_ip_wired, "modprobe -l | grep mac80211.ko") == "ERROR":
  81 + return "mac80211"
  82 + elif utils_config.exec_command_ssh(peer_ip_wired, "modprobe -l | grep b43.ko") == "ERROR":
  83 + return "b43"
  84 + else:
  85 + time.sleep(0.5)
  86 + peer_status = utils_config.check_ping(peer_ip)
  87 + if peer_status != "ok":
  88 + return "ERROR"
  89 + else:
  90 + return "ok"
  91 +
  92 +
... ...
utils_peers.pyc 0 → 100644
No preview for this file type
utils_peers.py~ 0 → 100644
  1 +++ a/utils_peers.py~
... ... @@ -0,0 +1,92 @@
  1 +import threading
  2 +import utils_config
  3 +import os, sys, time, re, subprocess
  4 +
  5 +# Global variables
  6 +path_module_b43 = "/lib/modules/2.6.36/kernel/drivers/net/wireless"
  7 +path_module_80211 = "/lib/modules/2.6.36/kernel/net/mac80211"
  8 +
  9 +# Run method executed by threads in order to configure one peer
  10 +# - Input: peer_ip, peer_ip_wired, bssid, rate, power, channel
  11 +# - Configure interfaces, load modules based on the selected mechanism, start peer and check it's configuration
  12 +def configure_peer(peer_ip, peer_ip_wired, bssid, rate, power, channel, mechanism):
  13 + print threading.currentThread().getName(), "configuring %s" % peer_ip_wired
  14 + reload_peer(peer_ip_wired)
  15 + set_mechanism(peer_ip_wired, mechanism)
  16 + start_ap(peer_ip_wired, peer_ip, bssid, rate, power, channel)
  17 +
  18 + peer_status = check_peer(peer_ip_wired, peer_ip)
  19 + if peer_status != "ok":
  20 + print threading.currentThread().getName(), "Peer (wired)%s not configured correctly. Problems with %s" % (peer_ip_wired, peer_status)
  21 + sys.exit()
  22 + else:
  23 + print "Peer configured - wired = %s, wlan0 = %s" % (peer_ip_wired, peer_ip)
  24 +
  25 +
  26 +# Reconfigure peer interface and enable mac80211 module
  27 +# - Input: peer ip wired
  28 +def reload_peer(peer_ip_wired):
  29 +
  30 + # kill all wpa supplicants
  31 + wpa_supplicant_pids = utils_config.exec_command(peer_ip_wired, "pgrep -x wpa_supplicant")
  32 + for pid in wpa_supplicant_pids:
  33 + pid = int(pid)
  34 + utils_config.exec_command(peer_ip_wired, ("kill -SIGTERM %d" % pid))
  35 + #print "Process wpa supplicand (pid = %d) killed" % pid
  36 +
  37 + # Reconfigure interface
  38 + #print "Reconfiguring peer %s Interface" % peer_ip_wired
  39 + utils_config.exec_command(peer_ip_wired, "rmmod b43 && sleep 1")
  40 + utils_config.exec_command(peer_ip_wired, "rmmod mac80211")
  41 + utils_config.exec_command(peer_ip_wired, "rm /lib/firmware/b43")
  42 + utils_config.exec_command(peer_ip_wired, "rm %s/b43/b43.ko" % path_module_b43)
  43 + utils_config.exec_command(peer_ip_wired, "rm %s/b43" % path_module_b43)
  44 + utils_config.exec_command(peer_ip_wired, "rm %s/mac80211.ko" % path_module_80211)
  45 + utils_config.exec_command(peer_ip_wired, "ln -s %s/mac80211.video.ko %s/mac80211.ko" % (path_module_80211, path_module_80211))
  46 + utils_config.exec_command(peer_ip_wired, "ln -s %s/b43.orig %s/b43" % (path_module_b43,path_module_b43))
  47 + utils_config.exec_command(peer_ip_wired, "modprobe mac80211")
  48 +
  49 +
  50 +# Enable b43 module using different sources depending of the selected mechanism
  51 +# - Input: Peer address, mechanism
  52 +def set_mechanism(peer_ip_wired, mechanism):
  53 + #print "Mechanism %s selected for the peer" % mechanism
  54 +
  55 + if mechanism == "LEGACY":
  56 + utils_config.exec_command(peer_ip_wired, "ln -s /lib/firmware/b43.legacy/ /lib/firmware/b43")
  57 + #utils_config.exec_command(peer_ip_wired, "ln -s %s/b43/b43-2.6.36-orig.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  58 + utils_config.exec_command(peer_ip_wired, "ln -s %s/b43/b43.orig-dmasingleworker.ko %s/b43/b43.ko" % (path_module_b43, path_module_b43))
  59 + utils_config.exec_command(peer_ip_wired, "modprobe b43 qos=1 && sleep 1")
  60 +
  61 +
  62 +# Start peer with the given configuration, set up wlan0 (peer_ip -> 192.168.98.xxx) and join to the AP
  63 +# - Input: Input: Peer address, rate, channel and power that we want to stablish in the AP
  64 +def start_ap(peer_ip_wired, peer_ip, bssid, rate, power, channel):
  65 + # Up wlan0 ,search and join AP
  66 + utils_config.exec_command(peer_ip_wired, "ifconfig wlan0 %s up" % peer_ip)
  67 + utils_config.exec_command(peer_ip_wired, "iwlist wlan0 scan | grep %s -C 5" % bssid)
  68 + utils_config.exec_command(peer_ip_wired, "wpa_supplicant -B -Dwext -iwlan0 -c/root/wpa_supplicant.conf")
  69 + utils_config.exec_command(peer_ip_wired, "iwconfig wlan0 rate %s fixed channel %s txpower %s fixed" % (rate, channel, power))
  70 +
  71 + #print "Configuring multicast route"
  72 + #utils_config.exec_command(peer_ip_wired, "route add -host 224.0.0.1 wlan0")
  73 +
  74 + #print "Setting arp table"
  75 + #utils_config.exec_command(peer_ip_wired, "/root/setarp.sh 192.168.98.10")
  76 +
  77 +# Check if all the configuration is correctly set
  78 +# - Input: Peer address (wired and wlan0 interface)
  79 +def check_peer(peer_ip_wired, peer_ip):
  80 + if utils_config.exec_command(peer_ip_wired, "modprobe -l | grep mac80211.ko") == "ERROR":
  81 + return "mac80211"
  82 + elif utils_config.exec_command(peer_ip_wired, "modprobe -l | grep b43.ko") == "ERROR":
  83 + return "b43"
  84 + else:
  85 + time.sleep(0.5)
  86 + peer_status = utils_config.check_ping(peer_ip)
  87 + if peer_status != "ok":
  88 + return "ERROR"
  89 + else:
  90 + return "ok"
  91 +
  92 +
... ...