• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from dataclasses import dataclass
16import hci_packets as hci
17import link_layer_packets as ll
18import unittest
19from hci_packets import ErrorCode
20from py.bluetooth import Address
21from py.controller import ControllerTest
22
23
24class Test(ControllerTest):
25
26    # LMP/LIH/BV-78-C [Role Switch at Setup, Central]
27    async def test(self):
28        # Test parameters.
29        controller = self.controller
30        acl_connection_handle = 0xefe
31        peer_address = Address('11:22:33:44:55:66')
32
33        controller.send_cmd(
34            hci.CreateConnection(bd_addr=peer_address,
35                                 packet_type=0x7fff,
36                                 page_scan_repetition_mode=hci.PageScanRepetitionMode.R1,
37                                 allow_role_switch=hci.CreateConnectionRoleSwitch.ALLOW_ROLE_SWITCH))
38
39        await self.expect_evt(hci.CreateConnectionStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
40
41        await self.expect_ll(
42            ll.Page(source_address=controller.address, destination_address=peer_address, allow_role_switch=True))
43
44        controller.send_ll(
45            ll.PageResponse(source_address=peer_address, destination_address=controller.address, try_role_switch=True))
46
47        await self.expect_evt(
48            hci.RoleChange(status=ErrorCode.SUCCESS, bd_addr=peer_address, new_role=hci.Role.PERIPHERAL))
49
50        await self.expect_evt(
51            hci.ConnectionComplete(status=ErrorCode.SUCCESS,
52                                   connection_handle=acl_connection_handle,
53                                   bd_addr=peer_address,
54                                   link_type=hci.LinkType.ACL,
55                                   encryption_enabled=hci.Enable.DISABLED))
56