1# Copyright 2024 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
15import hci_packets as hci
16import link_layer_packets as ll
17import unittest
18from hci_packets import ErrorCode
19from py.bluetooth import Address
20from py.controller import ControllerTest
21
22
23class Test(ControllerTest):
24
25    # HCI/AEN/BV-06-C [Public Keys]
26    #
27    # Verify that the IUT can generate a P-256 Public-Private key pair and
28    # return the P-256 Public Key
29    async def test(self):
30        controller = self.controller
31
32        controller.send_cmd(hci.LeReadLocalP256PublicKey())
33
34        await self.expect_evt(hci.LeReadLocalP256PublicKeyStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
35
36        first = await self.expect_evt(
37            hci.LeReadLocalP256PublicKeyComplete(status=ErrorCode.SUCCESS,
38                                                 key_x_coordinate=self.Any,
39                                                 key_y_coordinate=self.Any))
40
41        controller.send_cmd(hci.LeReadLocalP256PublicKey())
42
43        await self.expect_evt(hci.LeReadLocalP256PublicKeyStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1))
44
45        second = await self.expect_evt(
46            hci.LeReadLocalP256PublicKeyComplete(status=ErrorCode.SUCCESS,
47                                                 key_x_coordinate=self.Any,
48                                                 key_y_coordinate=self.Any))
49
50        self.assertTrue(
51            (first.key_x_coordinate, first.key_y_coordinate) != (second.key_x_coordinate, second.key_y_coordinate))
52