From bd25cf27dfb86241c3eb2bcff70d1e6a50dad20a Mon Sep 17 00:00:00 2001 From: Hui Peng Date: Fri, 24 Mar 2023 11:29:38 -0700 Subject: [PATCH] Fix a misconfig of HCI_PIN_Code_Reply_Command The pin_code field is of fixed length of 16 bytes --- bumble/hci.py | 2 +- tests/hci_test.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bumble/hci.py b/bumble/hci.py index a8403b94..9b5793d4 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -2102,7 +2102,7 @@ class HCI_Link_Key_Request_Negative_Reply_Command(HCI_Command): fields=[ ('bd_addr', Address.parse_address), ('pin_code_length', 1), - ('pin_code', '*'), + ('pin_code', 16), ], return_parameters_fields=[ ('status', STATUS_SPEC), diff --git a/tests/hci_test.py b/tests/hci_test.py index 65298851..af68e860 100644 --- a/tests/hci_test.py +++ b/tests/hci_test.py @@ -215,12 +215,18 @@ def test_HCI_Command(): # ----------------------------------------------------------------------------- def test_HCI_PIN_Code_Request_Reply_Command(): + pin_code = b'1234' + pin_code_length = len(pin_code) + # here to make the test pass, we need to + # pad pin_code, as HCI_Object.format_fields + # does not do it for us + padded_pin_code = pin_code + bytes(16 - pin_code_length) command = HCI_PIN_Code_Request_Reply_Command( bd_addr=Address( '00:11:22:33:44:55', address_type=Address.PUBLIC_DEVICE_ADDRESS ), - pin_code_length=4, - pin_code=b'1234', + pin_code_length=pin_code_length, + pin_code=padded_pin_code, ) basic_check(command)