Skip to content

Commit

Permalink
GATT: implement missing write callbacks...
Browse files Browse the repository at this point in the history
except allowlist
  • Loading branch information
ricardoquesada committed Jan 16, 2024
1 parent 615a88a commit 998ebea
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 118 deletions.
69 changes: 59 additions & 10 deletions src/components/bluepad32/bt/uni_bt_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,24 @@ static int att_write_callback(hci_con_handle_t con_handle,
client_connection_t* ctx;

switch (att_handle) {
case ATT_CHARACTERISTIC_4627C4A4_AC03_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Whether to enable BLE connections
if (buffer_size != 1 || offset != 0)
return 0;
bool enabled = buffer[0];
uni_bt_le_set_enabled(enabled);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC04_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Scan for new connections
if (buffer_size != 1 || offset != 0)
return 0;
bool enabled = buffer[0];
uni_bt_enable_new_connections_unsafe(enabled);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC06_46B9_B688_AFC5C1BF7F63_01_CLIENT_CONFIGURATION_HANDLE: {
// Notify connected devices
ctx = connection_for_conn_handle(con_handle);
if (!ctx)
break;
Expand All @@ -164,20 +181,56 @@ static int att_write_callback(hci_con_handle_t con_handle,
ctx->connection_handle);
break;
}
case ATT_CHARACTERISTIC_4627C4A4_AC03_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Whether to enable BLE connections
case ATT_CHARACTERISTIC_4627C4A4_AC07_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Mappings: Nintendo or Xbox: A,B,X,Y vs B,A,Y,X
if (buffer_size != 1 || offset != 0)
return 0;
uint8_t type = buffer[0];
if (type >= UNI_GAMEPAD_MAPPINGS_TYPE_COUNT)
return 0;
uni_gamepad_set_mappings_type(type);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC08_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Whether to enable Allowlist in connections
if (buffer_size != 1 || offset != 0)
return 0;
bool enabled = buffer[0];
uni_bt_le_set_enabled(enabled);
uni_bt_allowlist_set_enabled(enabled);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC04_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Scan for new connections
case ATT_CHARACTERISTIC_4627C4A4_AC09_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// TODO
// List of addresses in the allowlist.
return 0;
}
case ATT_CHARACTERISTIC_4627C4A4_AC0A_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Whether to enable Virtual Devices
if (buffer_size != 1 || offset != 0)
return 0;
bool enabled = buffer[0];
uni_bt_enable_new_connections_unsafe(enabled);
uni_virtual_device_set_enabled(enabled);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC0B_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Disconnect a device
if (buffer_size != 1 || offset != 0)
return 0;
int idx = buffer[0];
if (idx < 0 || idx >= CONFIG_BLUEPAD32_MAX_DEVICES)
return 0;
uni_hid_device_t* d = uni_hid_device_get_instance_for_idx(idx);
uni_hid_device_disconnect(d);
return 1;
}
case ATT_CHARACTERISTIC_4627C4A4_AC0C_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE: {
// Delete stored Bluetooth bond keys
if (buffer_size != 1 || offset != 0)
return 0;
bool delete = buffer[0];
if (!delete)
return 0;
uni_bt_del_keys_unsafe();
return 1;
}
default:
Expand Down Expand Up @@ -257,10 +310,6 @@ static uint16_t att_read_callback(hci_con_handle_t connection_handle,
// Delete stored Bluetooth bond keys
loge("BLE Service: 4627C4A4_AC0C_46B9_B688_AFC5C1BF7F63 does not support read\n");
break;
case ATT_CHARACTERISTIC_4627C4A4_AC0D_46B9_B688_AFC5C1BF7F63_01_VALUE_HANDLE:
// Reset device
loge("BLE Service: 4627C4A4_AC0D_46B9_B688_AFC5C1BF7F63 does not support read\n");
break;

case ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_01_VALUE_HANDLE:
break;
Expand Down
4 changes: 0 additions & 4 deletions src/components/bluepad32/bt/uni_bt_service.gatt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ CHARACTERISTIC, 4627C4A4-AC0B-46B9-B688-AFC5C1BF7F63, WRITE | DYNAMIC
// Delete stored Bluetooth bond keys
CHARACTERISTIC, 4627C4A4-AC0C-46B9-B688-AFC5C1BF7F63, WRITE | DYNAMIC

// Reset device
CHARACTERISTIC, 4627C4A4-AC0D-46B9-B688-AFC5C1BF7F63, WRITE | DYNAMIC


// add Battery Service
#import <battery_service.gatt>

Expand Down
Loading

0 comments on commit 998ebea

Please sign in to comment.