Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 064b49b4 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Implement additional LL advertising tests"

parents 8f69cfab 4f1cc97f
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
import lib_rootcanal_python3 as rootcanal
import hci_packets as hci
import link_layer_packets as ll
import unittest
from hci_packets import ErrorCode
from py.bluetooth import Address
from py.controller import ControllerTest


class Test(ControllerTest):
    # Test parameters.
    LL_advertiser_advInterval_MIN = 0x200
    LL_advertiser_advInterval_MAX = 0x200
    LL_advertiser_Adv_Channel_Map = 0x7

    # LL/DDI/ADV/BV-15-C [Discoverable Advertising Events]
    async def test(self):
        controller = self.controller

        # 1. Configure Lower Tester to monitor advertising packets from the IUT.
        # 2. Upper Tester enables discoverable undirected advertising in the IUT using a selected advertising
        # channel and a selected advertising interval between the minimum and maximum advertising.
        controller.send_cmd(
            hci.LeSetAdvertisingParameters(
                advertising_interval_min=self.LL_advertiser_advInterval_MIN,
                advertising_interval_max=self.LL_advertiser_advInterval_MAX,
                advertising_type=hci.AdvertisingType.ADV_SCAN_IND,
                own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS,
                advertising_channel_map=self.LL_advertiser_Adv_Channel_Map,
                advertising_filter_policy=hci.AdvertisingFilterPolicy.LISTED_SCAN_AND_CONNECT))

        await self.expect_evt(
            hci.LeSetAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingData(advertising_data=[]))

        await self.expect_evt(hci.LeSetAdvertisingDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 3. Lower Tester expects the IUT to send ADV_SCAN_IND packets starting an event on the selected
        # advertising channel.
        # 4. Expect the next event to start after advertising interval time calculated from the start of the first
        # packet.
        # 5. Repeat steps 3–4 until a number of advertising intervals (100) have been detected.
        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=[]),
                                 timeout=5)

        # 6. Upper Tester sends an HCI_LE_Set_Advertising_Enable command to disable advertising in the
        # IUT and receives an HCI_Command_Complete event from the IUT.
        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
+139 −0
Original line number Diff line number Diff line
import lib_rootcanal_python3 as rootcanal
import hci_packets as hci
import link_layer_packets as ll
import unittest
from hci_packets import ErrorCode
from py.bluetooth import Address
from py.controller import ControllerTest


class Test(ControllerTest):
    # Test parameters.
    LL_advertiser_advInterval_MIN = 0x200
    LL_advertiser_advInterval_MAX = 0x200
    LL_advertiser_Adv_Channel_Map = 0x7

    # LL/DDI/ADV/BV-16-C [Advertising Data: Discoverable]
    async def test(self):
        controller = self.controller

        # 1. Upper Tester enables discoverable undirected advertising in the IUT using a selected advertising
        # channel and a selected advertising interval between the minimum and maximum advertising
        # intervals.
        controller.send_cmd(
            hci.LeSetAdvertisingParameters(
                advertising_interval_min=self.LL_advertiser_advInterval_MIN,
                advertising_interval_max=self.LL_advertiser_advInterval_MAX,
                advertising_type=hci.AdvertisingType.ADV_SCAN_IND,
                own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS,
                advertising_channel_map=self.LL_advertiser_Adv_Channel_Map,
                advertising_filter_policy=hci.AdvertisingFilterPolicy.LISTED_SCAN_AND_CONNECT))

        await self.expect_evt(
            hci.LeSetAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 2. Upper Tester sends an HCI_LE_Set_Advertising_Data command to the IUT and receives an
        # HCI_Command_Complete in response. The data element used in the command is a number
        # indicating the length of the data. The data length is 1 byte.
        advertising_data = [1]
        controller.send_cmd(hci.LeSetAdvertisingDataRaw(advertising_data=advertising_data))

        await self.expect_evt(hci.LeSetAdvertisingDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 3. Upper Tester sends an HCI_LE_Set_Advertising_Enable command to the IUT to enable
        # advertising and receives an HCI_Command_Complete event in response.
        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 4. Lower Tester expects the IUT to send ADV_SCAN_IND packets including the data submitted in
        # step 3 starting an event on the selected advertising channel.
        # 5. Expect the following event to start after advertising interval time calculating from the start of the
        # first packet.
        # 6. Repeat steps 5–6 until a number of advertising intervals (50) have been detected.
        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=advertising_data),
                                 timeout=5)

        # 7. Upper Tester sends an HCI_LE_Set_Advertising_Enable command to the IUT to disable
        # advertising function and receives an HCI_Command_Complete event in response.
        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 8. Upper Tester sends an HCI_LE_Set_Advertising_Data to configure the IUT to send advertising
        # packets without advertising data and receives an HCI_Command_Complete event in response.
        controller.send_cmd(hci.LeSetAdvertisingData(advertising_data=[]))

        await self.expect_evt(hci.LeSetAdvertisingDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 9. Upper Tester sends an HCI_LE_Set_Advertising_Enable command to the IUT to enable
        # advertising and receives an HCI_Command_Complete event in response.
        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 10. Lower Tester expects the IUT to send ADV_SCAN_IND packets including no advertising data
        # starting an event on the selected advertising channel.
        # 11. Expect the next event to start after advertising interval time calculating from the start of the first
        # packet.
        # 12. Repeat steps 11–12 until a number of advertising intervals (50) have been detected.
        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=[]),
                                 timeout=5)

        # 13. Upper Tester sends an HCI_LE_Set_Advertising_Enable command to the IUT to disable
        # advertising and receives an HCI_Command_Complete event in response.
        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 14. Upper Tester sends an HCI_LE_Set_Advertising_Data command to the IUT and receives an
        # HCI_Command_Complete in response. The data element is a number indicating the length of the
        # data field in the first octet encoded unsigned least significant bit first and the rest of the octets
        # zeroes. The data length is 31 bytes.
        advertising_data = [31] + [0] * 30
        controller.send_cmd(hci.LeSetAdvertisingDataRaw(advertising_data=advertising_data))

        await self.expect_evt(hci.LeSetAdvertisingDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 15. Repeat steps 4–14.
        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=advertising_data),
                                 timeout=5)

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingData(advertising_data=[]))

        await self.expect_evt(hci.LeSetAdvertisingDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=[]),
                                 timeout=5)

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
+147 −0
Original line number Diff line number Diff line
import lib_rootcanal_python3 as rootcanal
import hci_packets as hci
import link_layer_packets as ll
import unittest
from typing import List
from hci_packets import ErrorCode
from py.bluetooth import Address
from py.controller import ControllerTest


class Test(ControllerTest):
    # Test parameters.
    LL_advertiser_advInterval_MIN = 0x200
    LL_advertiser_advInterval_MAX = 0x200
    LL_advertiser_Adv_Channel_Map = 0x7

    # LL/DDI/ADV/BV-17-C [Scan Request: Discoverable]
    async def test(self):
        controller = self.controller

        # 1. Upper Tester enables discoverable undirected advertising in the IUT using all supported
        # advertising channels and a selected advertising interval between the minimum and maximum
        # advertising.
        controller.send_cmd(
            hci.LeSetAdvertisingParameters(advertising_interval_min=self.LL_advertiser_advInterval_MIN,
                                           advertising_interval_max=self.LL_advertiser_advInterval_MAX,
                                           advertising_type=hci.AdvertisingType.ADV_SCAN_IND,
                                           own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS,
                                           advertising_channel_map=self.LL_advertiser_Adv_Channel_Map,
                                           advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES))

        await self.expect_evt(
            hci.LeSetAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 2. Configure Lower Tester to monitor the advertising and scan response procedures of the IUT. The
        # Lower Tester will send an SCAN_REQ packet on a selected supported advertising channel
        # (defined as an IXIT) and using a common public device address as parameter.
        peer_address = Address('aa:bb:cc:dd:ee:ff')

        # 3. Configure Scan Response Data in the IUT using device name length of 0 as response data.
        scan_response_data = []
        controller.send_cmd(hci.LeSetScanResponseDataRaw(advertising_data=scan_response_data))

        await self.expect_evt(hci.LeSetScanResponseDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 4. Lower Tester sends a SCAN_REQ packet on the selected advertising channel after receiving an
        # ADV_SCAN_IND packet from IUT on the advertising channel configured in step 3. The
        # SCAN_REQ is sent T_IFS after the end of an ADV_SCAN_IND packet.
        # 5. Lower Tester receives a SCAN_RSP packet from the IUT addressed to the Lower Tester T_IFS
        # after the end of the request packet.
        # 6. Repeat steps 4–5 30 times.
        await self.steps_4_6(peer_address=peer_address, scan_response_data=scan_response_data)

        # 7. Configure Scan Response Data in the IUT using device name length of 31 as response data.
        scan_response_data = [31] + [0] * 31
        controller.send_cmd(hci.LeSetScanResponseDataRaw(advertising_data=scan_response_data))

        await self.expect_evt(hci.LeSetScanResponseDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 8. Repeat steps 4–6.
        await self.steps_4_6(peer_address=peer_address, scan_response_data=scan_response_data)

        # 9. Configure Lower Tester to monitor the advertising and scan response procedures of the IUT. The
        # Lower Tester will send an SCAN_REQ packet on a selected supported advertising channel
        # (defined as an IXIT) and using a public device address that differs from the IUT address in the
        # most significant octet as parameter.
        peer_address = Address([
            controller.address.address[0] ^ 0xff, controller.address.address[1], controller.address.address[2],
            controller.address.address[3], controller.address.address[4], controller.address.address[5]
        ])

        # 10. Configure Scan Response Data in the IUT using device name length of 0 as response data.
        scan_response_data = []
        controller.send_cmd(hci.LeSetScanResponseDataRaw(advertising_data=scan_response_data))

        await self.expect_evt(hci.LeSetScanResponseDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 11. Repeat steps 4–6.
        await self.steps_4_6(peer_address=peer_address, scan_response_data=scan_response_data)

        # 12. Configure Scan Response Data in the IUT using device name length of 31 as response data.
        scan_response_data = [31] + [0] * 31
        controller.send_cmd(hci.LeSetScanResponseDataRaw(advertising_data=scan_response_data))

        await self.expect_evt(hci.LeSetScanResponseDataComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=True))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))

        # 13. Repeat steps 4–6.
        await self.steps_4_6(peer_address=peer_address, scan_response_data=scan_response_data)

        # Note: this last iteration is very redundant, not implementing it
        # to save on execution time.

        # 14. Configure Lower Tester to monitor the advertising and scan response procedures of the IUT. The
        # Lower Tester will send an SCAN_REQ packet on a selected supported advertising channel
        # (defined as an IXIT) and using a public device address with address that differs from the IUT
        # address in the most and least significant octets as parameter.

        # 15. Configure Scan Response Data in the IUT using device name length of 0 as response data.
        # 16. Repeat steps 4–6.

    async def steps_4_6(self, peer_address: Address, scan_response_data: List[int]):
        controller = self.controller

        # 4. Lower Tester sends a SCAN_REQ packet on the selected advertising channel after receiving an
        # ADV_SCAN_IND packet from IUT on the advertising channel configured in step 3. The
        # SCAN_REQ is sent T_IFS after the end of an ADV_SCAN_IND packet.
        # 5. Lower Tester receives a SCAN_RSP packet from the IUT addressed to the Lower Tester T_IFS
        # after the end of the request packet.
        # 6. Repeat steps 4–5 30 times.
        for n in range(3):
            await self.expect_ll(ll.LeLegacyAdvertisingPdu(source_address=controller.address,
                                                           advertising_address_type=ll.AddressType.PUBLIC,
                                                           advertising_type=ll.LegacyAdvertisingType.ADV_SCAN_IND,
                                                           advertising_data=[]),
                                 timeout=5)

            controller.send_ll(
                ll.LeScan(source_address=peer_address,
                          destination_address=controller.address,
                          scanning_address_type=ll.AddressType.PUBLIC,
                          advertising_address_type=ll.AddressType.PUBLIC))

            await self.expect_ll(ll.LeScanResponse(source_address=controller.address,
                                                   destination_address=peer_address,
                                                   advertising_address_type=ll.AddressType.PUBLIC,
                                                   scan_response_data=scan_response_data),
                                 timeout=5)

        controller.send_cmd(hci.LeSetAdvertisingEnable(advertising_enable=False))

        await self.expect_evt(hci.LeSetAdvertisingEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
+221 −0

File added.

Preview size limit exceeded, changes collapsed.

+117 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading