Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb117299 authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge changes I17ae1a8c,Iedacd854 into main

* changes:
  Move HCI event registration
  Remove no-op checks
parents 60e53f69 1fe0ea41
Loading
Loading
Loading
Loading
+1 −60
Original line number Diff line number Diff line
@@ -65,19 +65,12 @@ bool is_valid_event_code(bluetooth::hci::EventCode event_code) {
  switch (event_code) {
    case bluetooth::hci::EventCode::INQUIRY_COMPLETE:
    case bluetooth::hci::EventCode::INQUIRY_RESULT:
    case bluetooth::hci::EventCode::CONNECTION_COMPLETE:
    case bluetooth::hci::EventCode::CONNECTION_REQUEST:
    case bluetooth::hci::EventCode::DISCONNECTION_COMPLETE:
    case bluetooth::hci::EventCode::AUTHENTICATION_COMPLETE:
    case bluetooth::hci::EventCode::REMOTE_NAME_REQUEST_COMPLETE:
    case bluetooth::hci::EventCode::ENCRYPTION_CHANGE:
    case bluetooth::hci::EventCode::CHANGE_CONNECTION_LINK_KEY_COMPLETE:
    case bluetooth::hci::EventCode::CENTRAL_LINK_KEY_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE:
    case bluetooth::hci::EventCode::QOS_SETUP_COMPLETE:
    case bluetooth::hci::EventCode::COMMAND_COMPLETE:
    case bluetooth::hci::EventCode::COMMAND_STATUS:
    case bluetooth::hci::EventCode::HARDWARE_ERROR:
    case bluetooth::hci::EventCode::FLUSH_OCCURRED:
    case bluetooth::hci::EventCode::ROLE_CHANGE:
@@ -89,11 +82,9 @@ bool is_valid_event_code(bluetooth::hci::EventCode event_code) {
    case bluetooth::hci::EventCode::LINK_KEY_NOTIFICATION:
    case bluetooth::hci::EventCode::LOOPBACK_COMMAND:
    case bluetooth::hci::EventCode::DATA_BUFFER_OVERFLOW:
    case bluetooth::hci::EventCode::MAX_SLOTS_CHANGE:
    case bluetooth::hci::EventCode::READ_CLOCK_OFFSET_COMPLETE:
    case bluetooth::hci::EventCode::CONNECTION_PACKET_TYPE_CHANGED:
    case bluetooth::hci::EventCode::QOS_VIOLATION:
    case bluetooth::hci::EventCode::PAGE_SCAN_REPETITION_MODE_CHANGE:
    case bluetooth::hci::EventCode::FLOW_SPECIFICATION_COMPLETE:
    case bluetooth::hci::EventCode::INQUIRY_RESULT_WITH_RSSI:
    case bluetooth::hci::EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE:
@@ -112,20 +103,15 @@ bool is_valid_event_code(bluetooth::hci::EventCode event_code) {
    case bluetooth::hci::EventCode::ENHANCED_FLUSH_COMPLETE:
    case bluetooth::hci::EventCode::USER_PASSKEY_NOTIFICATION:
    case bluetooth::hci::EventCode::KEYPRESS_NOTIFICATION:
    case bluetooth::hci::EventCode::REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION:
    case bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_DATA_BLOCKS:
      return true;
    case bluetooth::hci::EventCode::VENDOR_SPECIFIC:
    case bluetooth::hci::EventCode::LE_META_EVENT:  // Private to hci
    case bluetooth::hci::EventCode::AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED:
    default:
      return false;
  }
  return false;
};

bool is_valid_subevent_code(bluetooth::hci::SubeventCode subevent_code) {
  switch (subevent_code) {
    case bluetooth::hci::SubeventCode::CONNECTION_COMPLETE:
    case bluetooth::hci::SubeventCode::CONNECTION_UPDATE_COMPLETE:
    case bluetooth::hci::SubeventCode::DATA_LENGTH_CHANGE:
    case bluetooth::hci::SubeventCode::ENHANCED_CONNECTION_COMPLETE:
@@ -166,25 +152,6 @@ bool is_valid_subevent_code(bluetooth::hci::SubeventCode subevent_code) {
  }
}

static bool event_already_registered_in_hci_layer(
    bluetooth::hci::EventCode event_code) {
  switch (event_code) {
    case bluetooth::hci::EventCode::COMMAND_COMPLETE:
    case bluetooth::hci::EventCode::COMMAND_STATUS:
    case bluetooth::hci::EventCode::CONNECTION_REQUEST:
    case bluetooth::hci::EventCode::PAGE_SCAN_REPETITION_MODE_CHANGE:
    case bluetooth::hci::EventCode::MAX_SLOTS_CHANGE:
    case bluetooth::hci::EventCode::LE_META_EVENT:
    case bluetooth::hci::EventCode::DISCONNECTION_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE:
    case bluetooth::hci::EventCode::REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION:
    case bluetooth::hci::EventCode::REMOTE_NAME_REQUEST_COMPLETE:
      return true;
    default:
      return false;
  }
}

static bool event_already_registered_in_controller_layer(
    bluetooth::hci::EventCode event_code) {
  switch (event_code) {
@@ -249,26 +216,6 @@ static bool subevent_already_registered_in_le_hci_layer(
  }
}

static bool event_already_registered_in_le_advertising_manager(
    bluetooth::hci::EventCode event_code) {
  for (auto event : bluetooth::hci::AclConnectionEvents) {
    if (event == event_code) {
      return true;
    }
  }
  return false;
}

static bool event_already_registered_in_le_scanning_manager(
    bluetooth::hci::EventCode event_code) {
  for (auto event : bluetooth::hci::AclConnectionEvents) {
    if (event == event_code) {
      return true;
    }
  }
  return false;
}

}  // namespace

namespace cpp {
@@ -544,12 +491,6 @@ void bluetooth::shim::hci_on_reset_complete() {
      continue;
    } else if (event_already_registered_in_controller_layer(event_code)) {
      continue;
    } else if (event_already_registered_in_hci_layer(event_code)) {
      continue;
    } else if (event_already_registered_in_le_advertising_manager(event_code)) {
      continue;
    } else if (event_already_registered_in_le_scanning_manager(event_code)) {
      continue;
    }

    cpp::register_event(event_code);