• 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-142-C [Reject Role Switch Request]
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.R0,
37                                 allow_role_switch=hci.CreateConnectionRoleSwitch.REMAIN_CENTRAL))
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=False))
43
44        controller.send_ll(
45            ll.PageResponse(source_address=peer_address, destination_address=controller.address, try_role_switch=False))
46
47        await self.expect_evt(
48            hci.ConnectionComplete(status=ErrorCode.SUCCESS,
49                                   connection_handle=acl_connection_handle,
50                                   bd_addr=peer_address,
51                                   link_type=hci.LinkType.ACL,
52                                   encryption_enabled=hci.Enable.DISABLED))
53
54        controller.send_cmd(hci.WriteLinkPolicySettings(connection_handle=acl_connection_handle,
55                                                        link_policy_settings=0))
56
57        await self.expect_evt(
58            hci.WriteLinkPolicySettingsComplete(status=ErrorCode.SUCCESS,
59                                                num_hci_command_packets=1,
60                                                connection_handle=acl_connection_handle))
61
62        controller.send_ll(ll.RoleSwitchRequest(source_address=peer_address, destination_address=controller.address))
63
64        await self.expect_ll(
65            ll.RoleSwitchResponse(source_address=controller.address,
66                                  destination_address=peer_address,
67                                  status=ErrorCode.ROLE_CHANGE_NOT_ALLOWED))
68