auth_reqs, "ERROR"))
self._device.security.SetAuthenticationRequirements(AuthenticationRequirementsMessage(requirement=auth_reqs))
- def send_ui_callback(self, address, callback_type, b, uid):
+ def __send_ui_callback(self, address, callback_type, b, uid, pin):
"""
Send a callback from the UI as if the user pressed a button on the dialog
"""
message_type=callback_type,
boolean=b,
unique_id=uid,
+ pin=bytes(pin),
address=common.BluetoothAddressWithType(
address=common.BluetoothAddress(address=address),
type=common.BluetoothAddressTypeEnum.PUBLIC_DEVICE_ADDRESS)))
assertThat(self._ui_event_stream).emits(get_unique_id)
return passkey
- def on_user_input(self, cert_address, reply_boolean, expected_ui_event):
+ def input_pin(self, cert_address, pin):
+ """
+ Respond to the UI event
+ """
+ self.on_user_input(
+ cert_address=cert_address, reply_boolean=True, expected_ui_event=UiMsgType.DISPLAY_PIN_ENTRY, pin=pin)
+
+ def on_user_input(self, cert_address, reply_boolean, expected_ui_event, pin=[]):
"""
Respond to the UI event
"""
logging.debug("DUT: Waiting for expected UI event")
assertThat(self._ui_event_stream).emits(get_unique_id)
- # TODO(optedoblivion): Make UiCallbackType dynamic for PASSKEY when added
- self.send_ui_callback(cert_address, UiCallbackType.YES_NO, reply_boolean, ui_id)
+ callback_type = UiCallbackType.YES_NO if len(pin) == 0 else UiCallbackType.PIN
+ self.__send_ui_callback(cert_address, callback_type, reply_boolean, ui_id, pin)
def get_address(self):
return self._device.address
_hci = None
+ MAX_PIN_LENGTH = 16
+ MIN_PIN_LENGTH = 1
+
def _enqueue_hci_command(self, command, expect_complete):
if (expect_complete):
self._hci.send_command_with_complete(command)
True)
self._enqueue_hci_command(hci_packets.UserPasskeyRequestReplyBuilder(peer, passkey), True)
- def send_ui_callback(self, address, callback_type, b, uid):
+ def input_pin(self, address, pin):
+ """
+ Pretend to answer the pairing dialog as a user
+ """
+ if len(pin) > self.MAX_PIN_LENGTH or len(pin) < self.MIN_PIN_LENGTH:
+ raise Exception("Pin code must be within range")
+ logging.info("Cert: Waiting for PIN request")
+ assertThat(self._hci_event_stream).emits(HciMatchers.EventWithCode(hci_packets.EventCode.PIN_CODE_REQUEST))
+ logging.info("Cert: Send user input PIN %s for %s" % (pin.decode(), address))
+ peer = address.decode('utf-8')
+ pin_list = list(pin)
+ # Pad
+ for i in range(self.MAX_PIN_LENGTH - len(pin_list)):
+ pin_list.append(0)
+ self._enqueue_hci_command(hci_packets.PinCodeRequestReplyBuilder(peer, len(pin), pin_list), True)
+
+ def __send_ui_callback(self, address, callback_type, b, uid, pin):
"""
Pretend to answer the pairing dailog as a user
"""