Skip to content

Commit

Permalink
Accept keyboards in BREDR code
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Oct 26, 2023
1 parent acca4e9 commit fa98bb5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion external/btstack
Submodule btstack updated 104 files
13 changes: 8 additions & 5 deletions src/components/bluepad32/uni_bt_bredr.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,24 +693,27 @@ void uni_bt_bredr_on_hci_pin_code_request(uint16_t channel, const uint8_t* packe
ARG_UNUSED(size);

// TODO: Move to uni_bt_bredr.c
bool is_mouse = false;
bool is_mouse_or_keyboard = false;

logi("--> HCI_EVENT_PIN_CODE_REQUEST\n");
hci_event_pin_code_request_get_bd_addr(packet, event_addr);
d = uni_hid_device_get_instance_for_address(event_addr);
if (!d) {
loge("Failed to get device for: %s, assuming it is not a mouse\n", bd_addr_to_str(event_addr));
} else {
uint32_t mouse_cod = UNI_BT_COD_MAJOR_PERIPHERAL | UNI_BT_COD_MINOR_MICE;
is_mouse = (d->cod & mouse_cod) == mouse_cod;
is_mouse_or_keyboard =
((d->cod & UNI_BT_COD_MAJOR_MASK) == UNI_BT_COD_MAJOR_PERIPHERAL) && // Is it a peripheral ?
(d->cod & UNI_BT_COD_MINOR_KEYBOARD_AND_MICE); // and is it a mouse or keyboard ?
}

if (is_mouse) {
// For mice, use "0000" as pins, which seems to be the expected one.
if (is_mouse_or_keyboard) {
// For mouse/keyboard, use "0000" as pins, which seems to be the expected one.
// "1234" could also be a valid pin.
logi("Using PIN code: '0000'\n");
gap_pin_code_response_binary(event_addr, (uint8_t*)"0000", 4);
} else {
// FIXME: Assumes incoming connection from Nintendo Wii using Sync.
// Move as a plugin to Wii code.
//
// From: https://wiibrew.org/wiki/Wiimote#Bluetooth_Pairing:
// If connecting by holding down the 1+2 buttons, the PIN is the
Expand Down
5 changes: 5 additions & 0 deletions src/components/bluepad32/uni_hid_parser_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,13 @@ void uni_hid_parser_mouse_parse_usage(uni_hid_device_t* d,
}

case 0xff00: // Logitech M-RCL124
// User defined
break;

case 0xff01: // Tank Mouse
// User defined
// fall-through

// unknown usage page
default:
logi("Mouse: Unsupported page: 0x%04x, usage: 0x%04x, value=0x%x\n", usage_page, usage, value);
Expand Down

0 comments on commit fa98bb5

Please sign in to comment.