コード例 #1
0
    def stop_hostapd(self):
        self.log.info('stop hostapd()')

        cmd_str = 'ps aux | grep hostapd | wc -l'
        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        if (int(sout) > 2):
            cmd_str = 'killall -9 hostapd'
            try:
                [rcode, sout, serr] = self.run_command(cmd_str)
            except Exception as e:
                fname = inspect.currentframe().f_code.co_name
                self.log.fatal("An error occurred in %s: %s" % (fname, e))
                raise exceptions.UPIFunctionExecutionFailedException(
                    func_name=fname, err_msg=str(e))

        cmd_str = 'ifconfig wlan0 down; ifconfig wlan0 up'
        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        self.log.info('stop hostapd() completed')

        return True
コード例 #2
0
 def set_inactive(self, radio_program_name):
     param_key_values = {}
     if self.radio_programs.has_key(radio_program_name):
         param_key_values["TAISC_ACTIVERADIOPROGRAM"] = self.radio_programs[
             'NO_MAC']
         node = self.node_factory.get_node(self.interface)
         if node != None:
             ret = node.write_parameters('taisc', param_key_values)
             if type(ret) == dict:
                 return ret["TAISC_ACTIVERADIOPROGRAM"]
             else:
                 fname = inspect.currentframe().f_code.co_name
                 self.log.fatal("Error executing function %s: %s!" %
                                (fname, ret))
                 raise exceptions.UPIFunctionExecutionFailedException(
                     func_name=fname, err_msg="Error executing function")
         else:
             fname = inspect.currentframe().f_code.co_name
             self.log.fatal("%s Interface %s does not exist!" %
                            (self.interface, fname))
             raise exceptions.InvalidArgumentException(
                 func_name=fname, err_msg="Interface does not exist")
     else:
         fname = inspect.currentframe().f_code.co_name
         self.log.warn("Wrong radio program name: %s" % radio_program_name)
         raise exceptions.InvalidArgumentException(
             func_name=fname, err_msg="Radio Program does not exist")
コード例 #3
0
 def start_monitor(self, driver, iface):
     self.log.info('start monitor setup')
     try:
         if driver == "ath9k":
             iface_mon = 'mon0'
             [rcode, sout, serr] = self.run_command(
                 'sudo iw dev {0} interface add {1} type monitor'.format(
                     iface, iface_mon))
             [rcode, sout, serr
              ] = self.run_command('sudo ifconfig {0} up'.format(iface_mon))
         elif driver == "b43":
             iface_mon = 'mon0'
             [rcode, sout, serr] = self.run_command(
                 'sudo iw dev {0} interface add {1} type monitor'.format(
                     iface, iface_mon))
             [rcode, sout, serr
              ] = self.run_command('sudo ifconfig {0} up'.format(iface_mon))
         else:
             self.log.info('driver not supported yet')
     except Exception as e:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("An error occurred in %s: %s" % (fname, e))
         raise exceptions.UPIFunctionExecutionFailedException(
             func_name=fname, err_msg=str(e))
     self.log.info('setup monitor completed')
コード例 #4
0
    def configure_radio_sensitivity(self, phy_dev, **kwargs):
        '''
            Configuring the carrier receiving sensitivity of the radio.
            Req.: modprobe ath5k/9k debug=0xffffffff

            #configuration of ath5k's ANI settings
            # disable ani
            echo "0" > /sys/kernel/debug/ieee80211/phy0/ath9k/ani

            supported ani modes:
            - 0 - disable ANI
            - tbd
        '''
        prefix = 'ath9k'
        ani_mode = kwargs.get('ani_mode')
        self.log.info('Setting ANI sensitivity w/ = %s' % str(ani_mode))

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/' + phy_dev + '/' + prefix +
                '/ani', 'w')
            myfile.write(ani_mode)
            myfile.close()
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return True
コード例 #5
0
    def set_per_flow_tx_power(self, flowId, txPower):
        self.log.debug('set_per_flow_tx_power on iface: {}'.format(
            self.interface))

        tcMgr = TrafficControl()
        markId = tcMgr.generateMark()
        self.setMarking(flowId,
                        table="mangle",
                        chain="POSTROUTING",
                        markId=markId)

        cmd_str = ('sudo iw ' + self.interface + ' info')
        cmd_output = subprocess.check_output(cmd_str,
                                             shell=True,
                                             stderr=subprocess.STDOUT)

        for item in cmd_output.split("\n"):
            if "wiphy" in item:
                line = item.strip()

        phyId = [int(s) for s in line.split() if s.isdigit()][0]

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/phy' + str(phyId) +
                '/ath9k/per_flow_tx_power', 'w')
            value = str(markId) + " " + str(txPower) + " 0"
            myfile.write(value)
            myfile.close()
            return "OK"
        except Exception as e:
            self.log.fatal("Operation not supported: %s" % e)
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name='radio.set_per_flow_tx_power',
                err_msg='cannot open file')
コード例 #6
0
    def clean_per_flow_tx_power_table(self):
        self.log.debug('clean_per_flow_tx_power_table on iface: {}'.format(
            self.interface))

        cmd_str = ('sudo iw ' + self.interface + ' info')
        cmd_output = subprocess.check_output(cmd_str,
                                             shell=True,
                                             stderr=subprocess.STDOUT)

        for item in cmd_output.split("\n"):
            if "wiphy" in item:
                line = item.strip()

        phyId = [int(s) for s in line.split() if s.isdigit()][0]

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/phy' + str(phyId) +
                '/ath9k/per_flow_tx_power', 'w')
            value = "0 0 0"
            myfile.write(value)
            myfile.close()
            return "OK"
        except Exception as e:
            self.log.fatal("Operation not supported: %s" % e)
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name='radio.clean_per_flow_tx_power_table',
                err_msg='cannot open file')
コード例 #7
0
    def getEdcaParameters(self):
        self.log.debug("ATH9K gets EDCA parameters for interface: {}".format(
            self.interface))

        cmd_str = ('sudo iw ' + self.interface + ' info')
        cmd_output = subprocess.check_output(cmd_str,
                                             shell=True,
                                             stderr=subprocess.STDOUT)

        for item in cmd_output.split("\n"):
            if "wiphy" in item:
                line = item.strip()

        phyId = [int(s) for s in line.split() if s.isdigit()][0]

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/phy' + str(phyId) +
                '/ath9k/txq_params', 'r')
            data = myfile.read()
            myfile.close()
            return data
        except Exception as e:
            self.log.fatal("Operation not supported: %s" % e)
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name='radio.get_mac_access_parameters',
                err_msg='cannot open file')
コード例 #8
0
    def configure_radio_sensitivity(self, phy_dev, **kwargs):
        '''
            Configuring the carrier receiving sensitivity of the radio.
            Req.: modprobe ath5k/9k debug=0xffffffff

            #configuration of ath5k's ANI settings
            echo "ani-off" > /sys/kernel/debug/ieee80211/phy0/ath5k/ani

            supported ani modes:
            - sens-low
            - sens-high
            - ani-off
            - ani-on
            - noise-low
            - noise-high
            - spur-low
            - spur-high
            - fir-low
            - fir-high
            - ofdm-off
            - ofdm-on
            - cck-off
            - cck-on

            Documentation from Linux Kernel:

            Adaptive Noise Immunity (ANI) controls five noise immunity parameters
            depending on the amount of interference in the environment, increasing
            or reducing sensitivity as necessary.

            The parameters are:

            - "noise immunity"
            - "spur immunity"
            - "firstep level"
            - "OFDM weak signal detection"
            - "CCK weak signal detection"

            Basically we look at the amount of ODFM and CCK timing errors we get and then
            raise or lower immunity accordingly by setting one or more of these
            parameters.
        '''
        prefix = 'ath5k'
        ani_mode = kwargs.get('ani_mode')
        self.log.info('Setting ANI sensitivity w/ = %s' % str(ani_mode))

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/' + phy_dev + '/' + prefix +
                '/ani', 'w')
            myfile.write(ani_mode)
            myfile.close()
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return True
コード例 #9
0
 def flush_iptables(self):
     try:
         [rcode, sout, serr] = self.run_command('sudo iptables -F')
         return sout
     except Exception as e:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("An error occurred in %s: %s" % (fname, e))
         raise exceptions.UPIFunctionExecutionFailedException(func_name=fname, err_msg=str(e))
コード例 #10
0
 def filter_mac(self, neighbor_mac_address):
     filter_cmd = "sudo iptables -I INPUT -i {} -m mac --mac-source {} " \
                  "-j DROP".format(self.interface, neighbor_mac_address)
     try:
         [rcode, sout, serr] = self.run_command(filter_cmd)
         return sout
     except Exception as e:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("An error occurred in %s: %s" % (fname, e))
         raise exceptions.UPIFunctionExecutionFailedException(func_name=fname, err_msg=str(e))
コード例 #11
0
 def set_ARP_entry(self, iface, mac_addr, ip_addr):
     """
         Manipulates the local ARP cache.
         todo: use Netlink API
     """
     try:
         [rcode, sout, serr] = self.run_command('sudo arp -s ' + ip_addr + ' -i '+ iface + ' ' + mac_addr)
         return sout
     except Exception as e:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("An error occurred in %s: %s" % (fname, e))
         raise exceptions.UPIFunctionExecutionFailedException(func_name=fname, err_msg=str(e))
コード例 #12
0
 def get_parameter(self, parameter_name):
     param_keys = [parameter_name]
     node = self.node_factory.get_node(self.interface)
     parameter_list = self.create_attribute_list_from_keys(
         node, param_keys, "parameter")
     ret = node.get_parameters(parameter_list)
     if type(ret) == dict:
         return ret[parameter_name]
     else:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("Error executing function %s: %s!" % (fname, ret))
         raise exceptions.UPIFunctionExecutionFailedException(
             func_name=fname, err_msg="Error executing function")
コード例 #13
0
 def set_rts_threshold(self, rts_threshold):
     self.log.info('setting set_rts_threshold(): %s->%s' %
                   (str(self.interface), str(rts_threshold)))
     try:
         [rcode, sout,
          serr] = self.run_command('sudo iwconfig {0} rts {1}'.format(
              self.interface, rts_threshold))
     except Exception as e:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("An error occurred in %s: %s" % (fname, e))
         raise exceptions.UPIFunctionExecutionFailedException(
             func_name=fname, err_msg=str(e))
     self.power = rts_threshold
コード例 #14
0
    def start_adhoc(self,
                    driver,
                    iface,
                    essid,
                    freq,
                    txpower,
                    rate,
                    ip_addr,
                    rts='off',
                    mac_address="aa:bb:cc:dd:ee:ff",
                    skip_reload=False):
        self.log.info('start adhoc setup')
        try:
            if driver == "ath9k":
                if skip_reload == False:
                    [rcode, sout, serr] = self.run_command(
                        'sudo rmmod ath9k ath9k_common ath9k_hw ath mac80211 cfg80211; sleep 1'
                    )
                    [rcode, sout,
                     serr] = self.run_command('sudo modprobe ath9k; sleep 1')
                else:
                    [rcode, sout, serr] = self.run_command(
                        'sudo iw {0} ibss leave'.format(iface))
                [rcode, sout, serr] = self.run_command(
                    'sudo iwconfig {0} mode ad-hoc; sudo ifconfig {0} {5} up;sudo iwconfig {0} txpower {3} fixed; sudo iwconfig {0} rate {4}M fixed; sudo iw dev {0} ibss join {1} {2} fixed-freq {6} '
                    .format(iface, essid, freq, txpower, rate, ip_addr,
                            mac_address))
                [rcode, sout,
                 serr] = self.run_command('sudo iwconfig {0} rts {1}'.format(
                     iface, rts))

            if driver == "b43":
                if skip_reload == False:
                    [rcode, sout, serr] = self.run_command('sudo rmmod b43')
                    [rcode, sout,
                     serr] = self.run_command('sudo modprobe b43 qos=0')
                else:
                    [rcode, sout, serr] = self.run_command(
                        'sudo iw {0} ibss leave'.format(iface))
                [rcode, sout, serr] = self.run_command(
                    'sudo iwconfig {0} mode ad-hoc; sudo ifconfig {0} {5} up;sudo iwconfig {0} txpower {3}; sudo iwconfig {0} rate {4}M fixed;sudo iw dev {0} ibss join {1} {2} fixed-freq {6}'
                    .format(iface, essid, freq, txpower, rate, ip_addr,
                            mac_address))

        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        self.log.info('adhoc setup completed')
コード例 #15
0
    def network_dump(self, iface):

        self.log.info('dump_network on interface %s' % (str(iface)))

        cmd_str = 'sudo iw dev ' + str(iface) + ' link'

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return sout
コード例 #16
0
    def connect_to_network(self, iface, ssid):

        self.log.info('connecting via to AP with SSID: %s->%s' %
                      (str(self.interface), str(ssid)))

        cmd_str = 'sudo iwconfig ' + str(iface) + ' essid ' + str(ssid)

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return True
コード例 #17
0
    def set_ip_address(self, iface, ip_address):

        self.log.info('setting ip address(): %s->%s' %
                      (str(self.interface), str(ip_address)))

        cmd_str = 'sudo ifconfig ' + str(iface) + ' ' + str(ip_address)

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return True
コード例 #18
0
    def uninstall_mac_processor(self, interface, hybridMac):

        self.log.info('Function: uninstallMacProcessor')

        #hybridMac = pickle.loads(mac_profile)

        # set allow all
        # generate configuration string
        conf_str = None
        for ii in range(hybridMac.getNumSlots()):  # for each slot
            # slot_id, mac_addr, tid_mask
            if conf_str is None:
                conf_str = str(ii) + "," + 'FF:FF:FF:FF:FF:FF' + "," + str(255)
            else:
                conf_str = conf_str + "#" + str(
                    ii) + "," + 'FF:FF:FF:FF:FF:FF' + "," + str(255)

        # command string
        terminate_str = 'TERMINATE'

        #  update MAC processor configuration
        try:
            # todo cache sockets!!!
            context = zmq.Context()
            socket = context.socket(zmq.REQ)
            socket.connect("tcp://localhost:" + str("1217"))
            #socket.connect("ipc:///tmp/localmacprocessor")

            # (1) set new config
            socket.send(conf_str)
            message = socket.recv()
            self.log.info("Received reply from HMAC: %s" % message)

            # give one second to settle down
            time.sleep(1)

            # (2) terminate MAC
            socket.send(terminate_str)
            message = socket.recv()
            self.log.info("Received reply from HMAC: %s" % message)

            return True
        except zmq.ZMQError as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))
コード例 #19
0
    def set_modulation_rate(self, rate_Mbps):

        self.log.info('setting modulation rate(): %s->%s' %
                      (str(self.interface), str(rate_Mbps)))

        cmd_str = 'sudo iwconfig ' + self.interface + ' rate ' + \
                  str(rate_Mbps) + 'M' + ' fixed'

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        self.modulation_rate = rate_Mbps
コード例 #20
0
    def start_hostapd(self, file_path):
        self.log.info('start hostapd()')

        cmd_str = 'sudo hostapd -B ' + str(file_path)
        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
            #sp = subprocess.Popen(cmd_str, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            #out, err = sp.communicate()
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        self.log.info('start hostapd() completed')

        return True
コード例 #21
0
    def set_tx_power(self, power_dBm):

        self.log.info('setting set_power(): %s->%s' %
                      (str(self.interface), str(power_dBm)))

        cmd_str = 'sudo iw dev ' + self.interface + ' set txpower fixed ' + \
                  str(power_dBm * 100)

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        self.power = power_dBm
コード例 #22
0
    def get_info_of_connected_devices(self):
        '''
            Returns information about associated STAs for a node running in AP mode
            tbd: use Netlink API
        '''

        self.log.info(
            "WIFI Module get info on associated clients on interface: {}".
            format(self.interface))

        try:
            [rcode, sout, serr
             ] = self.run_command('iw dev ' + self.interface + ' station dump')

            # mac_addr -> stat_key -> list of (value, unit)
            res = {}
            sout_arr = sout.split("\n")

            for line in sout_arr:
                s = line.strip()
                if s == '':
                    continue
                if "Station" in s:
                    arr = s.split()
                    mac_addr = arr[1].strip()
                    res[mac_addr] = {}
                else:
                    arr = s.split(":")
                    key = arr[0].strip()
                    val = arr[1].strip()

                    arr2 = val.split()
                    val2 = arr2[0].strip()

                    if len(arr2) > 1:
                        unit = arr2[1].strip()
                    else:
                        unit = None

                    res[mac_addr][key] = (val2, unit)
            return res
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))
コード例 #23
0
    def set_channel(self, channel):

        self.log.info('setting channel(): %s->%s' %
                      (str(self.interface), str(channel)))

        cmd_str = 'sudo iwconfig ' + self.interface + ' channel ' + str(
            channel)

        try:
            [rcode, sout, serr] = self.run_command(cmd_str)
            self.channel = channel
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))

        return True
コード例 #24
0
    def get_entry_of_connected_devices(self, key):

        try:
            res = self.get_info_of_connected_devices()

            rv = {}
            for mac_addr in res:
                value = res[mac_addr][key]
                self.log.info('%s -> %s' % (mac_addr, value))
                rv[mac_addr] = value

            # dict of mac_addr -> value
            return rv
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))
コード例 #25
0
    def install_mac_processor(self, interface, hybridMac):

        self.log.info('Function: installMacProcessor')
        #self.log.info('margs = %s' % str(myargs))

        # hybridMac = pickle.loads(mac_profile)

        conf_str = None
        for ii in range(hybridMac.getNumSlots()):  # for each slot
            ac = hybridMac.getAccessPolicy(ii)
            entries = ac.getEntries()

            for ll in range(len(entries)):
                entry = entries[ll]

                # slot_id, mac_addr, tid_mask
                if conf_str is None:
                    conf_str = str(ii) + "," + str(entry[0]) + "," + str(
                        entry[1])
                else:
                    conf_str = conf_str + "#" + str(ii) + "," + str(
                        entry[0]) + "," + str(entry[1])

        # set-up executable here. note: it is platform-dependent

        exec_file = str(os.path.join(
            self.get_platform_path_hybrid_MAC())) + '/hybrid_tdma_csma_mac'

        processArgs = str(exec_file) + " -d 0 " + " -i" + str(
            interface) + " -f" + str(
                hybridMac.getSlotDuration()) + " -n" + str(
                    hybridMac.getNumSlots()) + " -c" + conf_str
        self.log.info('Calling hybrid mac executable w/ = %s' %
                      str(processArgs))

        try:
            # run as background process
            subprocess.Popen(processArgs.split(), shell=False)
            return True
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))
コード例 #26
0
    def update_mac_processor(self, interface, hybridMac):

        self.log.info('Function: updateMacProcessor')
        self.log.info('margs = %s' % str(myargs))

        #hybridMac = pickle.loads(mac_profile)

        # generate configuration string
        conf_str = None
        for ii in range(hybridMac.getNumSlots()):  # for each slot
            ac = hybridMac.getAccessPolicy(ii)
            entries = ac.getEntries()

            for ll in range(len(entries)):
                entry = entries[ll]

                # slot_id, mac_addr, tid_mask
                if conf_str is None:
                    conf_str = str(ii) + "," + str(entry[0]) + "," + str(
                        entry[1])
                else:
                    conf_str = conf_str + "#" + str(ii) + "," + str(
                        entry[0]) + "," + str(entry[1])

        #  update MAC processor configuration
        try:
            # todo cache sockets!!!
            context = zmq.Context()
            socket = context.socket(zmq.REQ)
            socket.connect("tcp://localhost:" +
                           str(LOCAL_MAC_PROCESSOR_CTRL_PORT))
            #socket.connect("ipc:///tmp/localmacprocessor")

            socket.send(conf_str)
            message = socket.recv()
            self.log.info("Received reply from HMAC: %s" % message)
            return True
        except zmq.ZMQError as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))
コード例 #27
0
 def get_txchannel(self):
     param_keys = []
     param_keys = ["IEEE802154_phyCurrentChannel"]
     node = self.node_factory.get_node(self.interface)
     if node != None:
         ret = node.read_parameters('taisc', param_keys)
         if type(ret) == dict:
             return ret["IEEE802154_phyCurrentChannel"]
         else:
             fname = inspect.currentframe().f_code.co_name
             self.log.fatal("Error executing function %s: %s!" %
                            (fname, ret))
             raise exceptions.UPIFunctionExecutionFailedException(
                 func_name=fname, err_msg="Error executing function")
     else:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("%s Interface %s does not exist!" %
                        (self.interface, fname))
         raise exceptions.InvalidArgumentException(
             func_name=fname, err_msg="Interface does not exist")
コード例 #28
0
 def set_txpower(self, power_dBm):
     param_key_values = {}
     param_key_values['IEEE802154_phyTXPower'] = power_dBm
     node = self.node_factory.get_node(self.interface)
     if node != None:
         ret = node.write_parameters('taisc', param_key_values)
         if type(ret) == dict:
             return ret["IEEE802154_phyTXPower"]
         else:
             fname = inspect.currentframe().f_code.co_name
             self.log.fatal("Error executing function %s: %s!" %
                            (fname, ret))
             raise exceptions.UPIFunctionExecutionFailedException(
                 func_name=fname, err_msg="Error executing function")
     else:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("%s Interface %s does not exist!" %
                        (self.interface, fname))
         raise exceptions.InvalidArgumentException(
             func_name=fname, err_msg="Interface does not exist")
コード例 #29
0
 def get_active(self):
     param_keys = []
     param_keys = ["TAISC_ACTIVERADIOPROGRAM"]
     node = self.node_factory.get_node(self.interface)
     if node != None:
         ret = node.read_parameters('taisc', param_keys)
         if type(ret) == dict:
             return self.radio_program_names[
                 ret["TAISC_ACTIVERADIOPROGRAM"]]
         else:
             fname = inspect.currentframe().f_code.co_name
             self.log.fatal("Error executing function %s: %s!" %
                            (fname, ret))
             raise exceptions.UPIFunctionExecutionFailedException(
                 func_name=fname, err_msg="Error executing function")
     else:
         fname = inspect.currentframe().f_code.co_name
         self.log.fatal("%s Interface %s does not exist!" %
                        (self.interface, fname))
         raise exceptions.InvalidArgumentException(
             func_name=fname, err_msg="Interface does not exist")
コード例 #30
0
    def add_device_to_blacklist(self, iface, sta_mac_addr):
        """
            Blacklist a given STA in the AP, i.e. any request for association by the STA will be ignored by the AP.
            tbd: what is -p ?? Please simplify
        """

        exec_file = str(os.path.join(
            self.getPlatformPathHandover())) + '/hostapd_cli'
        args = '-p /tmp/hostapd-' + iface + ' blacklist_sta'

        command = exec_file + ' ' + args + ' ' + sta_mac_addr
        self.log.debug('Blacklist node %s on iface %s' % (sta_mac_addr, iface))
        self.log.debug('exec %s' % command)

        try:
            [rcode, sout, serr] = self.run_command(command)
            return sout
        except Exception as e:
            fname = inspect.currentframe().f_code.co_name
            self.log.fatal("An error occurred in %s: %s" % (fname, e))
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name=fname, err_msg=str(e))