예제 #1
0
    def _get_bssid_from_ssid(self, ssid, interface="wlan0"):
        """
        Get BSSID from SSID
        :type ssid: str
        :param ssid: The access point's SSID

        :rtype: str
        :return: The access point's mac address (BSSID)

        :type interface: str
        :param interface: interface name (wlan0/wlan1 etc...)

        """
        if (not ssid):
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                     ssid)

        cmd = "adb shell wpa_cli IFNAME=%s scan_result" % interface
        results = self._exec(cmd, timeout=5, wait_for_response=True)
        # Align all the carriage returns to \n to make it work on all OS and all adb connect method
        results = results.replace('\r', '\n')
        bssid = ''
        for line in results.split('\n'):
            if line.endswith(ssid):
                bssid = str(line).split()[0]
                break

        if (not NetworkingUtil.is_valid_mac_address(bssid)):
            msg = "Unable to get BSSID from SSID '%s' (result = %s)" % (ssid,
                                                                        bssid)
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        return bssid
예제 #2
0
    def bt_find_device(self, remote_device_info):
        """
        Looks for a Bluetooth device.

        :type remote_device_info: str
        :param remote_device_info: Name or address of the device

        :rtype: boolean
        :return: True if found , False otherwise
        """
        bt_found = False
        bt_devices_list = self.bt_scan_devices()

        if NetworkingUtil.is_valid_mac_address(remote_device_info):
            # remote_device_info is a bd address
            for device in bt_devices_list:
                if (str(device.address).upper()
                        == str(remote_device_info).upper()
                        or str(device.name).upper()
                        == str(remote_device_info).upper()):
                    bt_found = True
                    self._logger.info("Device %s found" % remote_device_info)
                    break
        else:
            # remote_device_info is not a valid bd address, maybe a name !
            for device in bt_devices_list:
                if str(device.name) == str(remote_device_info):
                    bt_found = True
                    self._logger.info("Device %s found" % remote_device_info)
                    break

        if not bt_found:
            self._logger.info("Device " + remote_device_info +
                              " is not in range !")
        return bt_found
예제 #3
0
 def _validate_bt_address(self, remote_device_addr):
     """
     Validate bt address
     """
     # Check address format
     remote_device_addr = str(remote_device_addr).upper()
     if not NetworkingUtil.is_valid_mac_address(remote_device_addr):
         raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, "BD address \'%s\' has a bad format!" \
                                  % remote_device_addr)
예제 #4
0
    def get_default_addr(self):
        """
        Get the default BD address (persistant address)

        :rtype: str
        :return: default BD address. format: 12:34:56:78:9A:BC
                 otherwise return empty str
        """

        BDADDR_PATH_PROPERTY = "ro.bt.bdaddr_path"
        PERSIST_BDROID_ADDR = "persist.service.bdroid.bdaddr"

        device_properties = DeviceManager().get_device_properties(
            self._device.get_name())

        # 1. Default from bd_addr.conf file if it exists and not null
        if BDADDR_PATH_PROPERTY in device_properties:
            bdconf_path = device_properties.get(BDADDR_PATH_PROPERTY)
            cmd = "adb shell cat %s" % bdconf_path
            bdconf = self._exec(cmd)
            bdconf = str(bdconf).upper().strip()
            if bdconf.find("NO SUCH FILE OR DIRECTORY"):
                bdconf = ""
            if bdconf not in ["", "00:00:00:00:00:00"]:
                self._logger.debug("Default BD Address from %s is <%s>" %
                                   (bdconf_path, bdconf))
                if NetworkingUtil.is_valid_mac_address(bdconf):
                    return bdconf
                else:
                    return ""

        # 2. Default from persist.service.bdroid.bdaddr property
        if PERSIST_BDROID_ADDR in device_properties:
            bdaddr = device_properties.get(PERSIST_BDROID_ADDR)
        else:
            bdaddr = ""
        bdaddr = str(bdaddr).upper().strip()
        self._logger.debug(
            "Default BD Address from persist.service.bdroid.bdaddr is <%s>" %
            bdaddr)
        if NetworkingUtil.is_valid_mac_address(bdaddr):
            return bdaddr
        else:
            return ""
예제 #5
0
    def set_up(self):
        """
        Initialize the test
        """
        # pylint: disable=E1101
        UseCaseBase.set_up(self)

        # Check sw release in DUT is engineering build
        if "eng" not in str(self._device.device_properties.sw_release):
            msg = "TC blocked by userdebug sw release"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check prov_mode value
        self._prov_mode = str(self._prov_mode).lower()
        if self._prov_mode not in ["no_prov", "prov"]:
            msg = "PROV_MODE value <%s> is not supported" % str(
                self._prov_mode)
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # turn on bluetooth
        self._logger.info("Turn on Bluetooth adapters")
        self._bt_api.set_bt_power("on")
        time.sleep(self._wait_btwn_cmd)
        if self._bt_api.get_bt_power_status() != str(BT_STATE.STATE_ON):
            msg = "set BT ON failure"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        # Check address format
        if self._prov_mode == "prov":
            self._original_addr = self._original_addr.upper().strip()
            bdaddr_z = self._original_addr.replace('X', '0')
            if not NetworkingUtil.is_valid_mac_address(bdaddr_z):
                new_msg = "BAD format of NEW_ADDR parameter: <%s>" % self._original_addr
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         new_msg)
        else:
            # Check default BD_address after BT is ON
            self._default_addr = self._bt_api.get_default_addr()
            if self._default_addr == "":
                new_msg = "Unable to get default BD address <%s>" % self._default_addr
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         new_msg)

        return Global.SUCCESS, "No errors"
예제 #6
0
    def ble_scan_filter_address(self, remote_device_address, scan_mode,
                                timeout):
        """
        BLE Filtered scanning for a device address.

        :rtype: str
        :return: Found Bluetooth Device
        """
        bt_found = False
        btdev = BluetoothDevice()

        method = "filterLeAddress"
        args = "--es address %s --ei scanMode %s --ei cmdTimeout %s" % (
            remote_device_address, scan_mode, timeout)

        output = self._internal_exec_v2(
            self._BLUETOOTH_LE_MODULE,
            method,
            args,
            timeout=self.millis_to_seconds(int(timeout)) + 5,
            is_system=True)

        if NetworkingUtil.is_valid_mac_address(remote_device_address):
            # remote_device_info is a bd address
            for device in output:
                if (str(device.address).upper()
                        == str(remote_device_address).upper()
                        or str(device.name).upper()
                        == str(remote_device_address).upper()):
                    bt_found = True
                    self._logger.info("Device %s found" %
                                      remote_device_address)

        if "Address" in output:
            btdev.address = output["Address"]
        if "Name" in output:
            btdev.name = output["Name"]

        self._logger.info("Device name: " + btdev.name + " address: " +
                          btdev.address)

        if not bt_found:
            self._logger.info("Device " + remote_device_address +
                              " is not in range or could not be filtered!")
            return False
        else:
            return btdev
예제 #7
0
    def ble_gatt_client_read_characteristic(self, address):
        """

        :return:
        """
        method = "readGattCharacteristic"
        args = "--es address %s" % address

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
예제 #8
0
    def ble_gatt_client_discover_services(self, address):
        """

        :return:
        """
        method = "discoverGattServices"
        args = "--es address %s" % address

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
예제 #9
0
    def ble_gatt_client_connect_to_server(self, address):
        """

        :param address:
        :return:
        """
        method = "connectGatt"
        args = "--es address %s" % address
        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
예제 #10
0
    def ble_gatt_client_reliable_write(self, address, reliable_write_value):
        """

        :return:
        """
        method = "gattReliableWrite"
        args = "--es address %s --es reliableWriteValue %s" % (
            address, reliable_write_value)

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
예제 #11
0
    def ble_gatt_client_write_descriptor(self, address,
                                         write_descriptor_value):
        """

        :return:
        """
        method = "writeGattDescriptor"
        args = "--es address %s --es writeDescriptorValue %s" % (
            address, write_descriptor_value)

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
    def set_up(self):
        """
        Initialize the test
        """
        LiveDualPhoneBTBase.set_up(self)

        # Check BT addresses validity
        if not NetworkingUtil.is_valid_mac_address(self._phone1_addr):
            msg = "Wrong MAC address for PHONE1 [%s]" % self._phone1_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)
        if not NetworkingUtil.is_valid_mac_address(self._phone2_addr):
            msg = "Wrong MAC address for PHONE2 [%s]" % self._phone2_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Set sender/receiver APIs and varialbes
        if self._direction.upper() == "UL":
            self._sender_api = self._bt_api
            self._sender_add = self._phone1_addr
            self._sender_device = self._device
            self._sender_phonesys_api = self._phonesystem_api
            self._receiver_api = self._bt_api2
            self._receiver_add = self._phone2_addr
            self._receiver_device = self._phone2
            self._receiver_phonesys_api = self._phonesystem2_api
            self._fullpath_filename = self._multimedia_path1 + "/" \
                + self._filename
            self._filesize = self._phonesystem_api.\
                get_file_size(self._fullpath_filename)
        elif self._direction.upper() == "DL":
            self._sender_api = self._bt_api2
            self._sender_add = self._phone2_addr
            self._sender_device = self._phone2
            self._sender_phonesys_api = self._phonesystem2_api
            self._receiver_api = self._bt_api
            self._receiver_add = self._phone1_addr
            self._receiver_device = self._device
            self._receiver_phonesys_api = self._phonesystem_api
            self._fullpath_filename = self._multimedia_path2 + "/" \
                + self._filename
            self._filesize = self._phonesystem2_api.\
                get_file_size(self._fullpath_filename)
        else:
            msg = "Invalid DIRECTION parameter [%s]" % self._direction
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Control the existence of the file to send and get the file size \
        # in order to determine the timeout duration
        if self._filesize < 0:
            msg = "Filesize is not accessible. " \
                + "File is probably missing on TX device"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.FEATURE_NOT_AVAILABLE,
                                     msg)

        self._timeout = int(
            self._filesize / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20

        # Set receiver discoverable by sender
        self._receiver_api.set_bt_discoverable("connectable", 0)
        # First Scan devices around to speed-up run_test
        self._sender_api.bt_scan_devices()

        # unlock screen and set display ON
        # Mandatory prior to use bt_opp_send_file UECmd
        self._sender_phonesys_api.display_on()
        self._sender_phonesys_api.set_phone_lock(0)

        return Global.SUCCESS, "No errors"
    def set_up(self):
        """
        Initialize the test
        """
        LiveDualPhoneBTBase.set_up(self)

        # Check BT addresses validity
        if not NetworkingUtil.is_valid_mac_address(self._phone1_addr):
            msg = "Wrong MAC address for PHONE1 [%s]" % self._phone1_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)
        if not NetworkingUtil.is_valid_mac_address(self._phone2_addr):
            msg = "Wrong MAC address for PHONE2 [%s]" % self._phone2_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Set sender/receiver APIs and variables
        if self._direction == self.UPLOAD:
            self._sender_api = self._bt_api
            self._sender_add = self._phone1_addr
            self._sender_device = self._device
            self._sender_phonesys_api = self._phonesystem_api
            self._receiver_api = self._bt_api2
            self._receiver_add = self._phone2_addr
            self._receiver_device = self._phone2
            self._receiver_phonesys_api = self._phonesystem2_api
            (self._fullpath_filenames, expected_size1) = self \
                ._process_files(self._multimedia_path1, self._file_list, False)

            (self._fp_filename_other_dir, expected_size2) = self \
                ._process_files(self._multimedia_path2, self._file_list, True)
        elif self._direction == self.DOWNLOAD:
            self._sender_api = self._bt_api2
            self._sender_add = self._phone2_addr
            self._sender_device = self._phone2
            self._sender_phonesys_api = self._phonesystem2_api
            self._receiver_api = self._bt_api
            self._receiver_add = self._phone1_addr
            self._receiver_device = self._device
            self._receiver_phonesys_api = self._phonesystem_api
            (self._fullpath_filenames, expected_size1) = self \
                ._process_files(self._multimedia_path2, self._file_list, False)

            (self._fp_filename_other_dir, expected_size2) = self \
                ._process_files(self._multimedia_path1, self._file_list, True)
        else:
            msg = "Invalid DIRECTION parameter [%s]" % self._direction
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        if expected_size1 != expected_size2:
            # same files, hence must have same size!!
            msg = "Files size are supposed to be the same!!"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        self._timeout1 = int(
            expected_size1 / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20
        self._timeout2 = int(
            expected_size2 / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20

        # Set receiver discoverable by sender
        self._receiver_api.set_bt_discoverable("connectable", 0)
        # First Scan devices around to speed-up run_test
        self._sender_api.bt_scan_devices()

        # unlock screen and set display ON
        # Mandatory prior to use bt_opp_send_file UECmd
        self._sender_phonesys_api.display_on()
        self._sender_phonesys_api.set_phone_lock(0)

        # Process the bidirectional transfer
        if self._is_bidirectional:
            # Set sender discoverable by receiver
            self._sender_api.set_bt_discoverable("connectable", 0)
            self._receiver_api.bt_scan_devices()
            self._receiver_phonesys_api.display_on()
            self._receiver_phonesys_api.set_phone_lock(0)

        # Check throughput data validity
        if self._tp_enable:
            msg = "Throughput measurement is enabled"
            self._logger.info(msg)
            # Read the throughput targets
            self._throughput_targets = ConfigsParser("BT_Throughput_Targets").\
                parse_bt_targets(self._device.get_phone_model(), "OPP")

            # Verify validity of margin parameter
            if self._tp_margin.isdigit():
                self._throughtput_margin = int(self._tp_margin)
            else:
                msg = "ERROR_MARGIN parameter is not valid: <%s>" % self._tp_margin
                self._logger.error(msg)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)

            # Initialize Average tp measure
            self._reset_tp_meas(self._file_list, self._direction,
                                self._is_bidirectional)

        return Global.SUCCESS, "No errors"
예제 #14
0
    def set_up(self):
        """
        Initialize the test
        """
        LiveBTBase.set_up(self)

        # Check audio command list is not empty
        if (len(self._audiocmd_list) == 1
                and self._audiocmd_list[0].strip() == ""):
            msg = "MUSIC_CONTROL_SEQUENCE cannot be empty"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check CONNECT_INITIATOR value is valid
        self._connector = self._connector.upper()
        if self._connector not in ("DUT", "HEADSET"):
            msg = "BAD CONNECT_INITIATOR value. only DUT or HEADSET expected"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Get Bluetooth instance
        self._bt_headset = self._em.get_bluetooth_headset("BT_HEADSET")

        # BD address of Headset
        self._hsaddr = self._bt_headset.get_bdaddress()

        if self._hsaddr.lower() in ["none", "", "00:00:00:00:00:00"]:
            msg = "No BD addr defined for BT HEADSET in bench_config"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check BT address validity
        if not NetworkingUtil.is_valid_mac_address(self._hsaddr):
            msg = "Wrong BD address for HEADSET [%s]" % self._hsaddr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Initialize BT headset to OFF state
        self._init_headset_off()
        time.sleep(5)

        # In both case (connector DUT or HEADSET), DUT shall initiates pairing
        # Put HEADSET in pairing mode (HS shall be OFF prior to that step)
        self._logger.info("Set headset in pairable mode")
        self._bt_headset.set_discoverable()
        time.sleep(1)

        # DUT scan to discover remote headset
        if not self._bt_api.bt_find_device(self._hsaddr):
            msg = "Headset <%s> not found" % self._hsaddr
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        # DUT initiates pairing to headset
        pair_result = self._bt_api.pair_to_device(self._hsaddr, 1)

        # pylint: disable=E1101
        if pair_result[0] == BT_BOND_STATE.BOND_BONDED:
            msg = "Pairing with headset succeeded"
            self._logger.info(msg)
        elif pair_result[0] == BT_BOND_STATE.BOND_NONE:
            msg = "Pairing with headset failed"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            msg = "[PHONE1]Unexpected return value %s" % pair_result
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        if self._connector == "HEADSET":
            # If Initiator is HEADSET, DUT shall be discoverable
            self._bt_api.set_bt_discoverable("connectable", 0)

        return Global.SUCCESS, "No errors"