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

Commit 2752bf29 authored by Aritra Sen's avatar Aritra Sen
Browse files

Move L2CAP CoC specific code to btif_sock_l2cap.

This helps us keep more consistent boundaries. Keeping the flag reading and setting in the same file helps with reading and debugging.

Bug: 328310541
Test: m -j $(nproc)
Flag: EXEMPT ; simple moving of code inside the same layer (no thread jumps or anything of that sorts)
Change-Id: I8c7ea74fc3498ec99ecd260edc4df64bd5786ba7
parent 82e31399
Loading
Loading
Loading
Loading
+2 −14
Original line number Original line Diff line number Diff line
@@ -269,7 +269,6 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,


  *sock_fd = INVALID_FD;
  *sock_fd = INVALID_FD;
  bt_status_t status = BT_STATUS_FAIL;
  bt_status_t status = BT_STATUS_FAIL;
  int original_channel = channel;


  log_socket_connection_state(RawAddress::kEmpty, 0, type,
  log_socket_connection_state(RawAddress::kEmpty, 0, type,
                              android::bluetooth::SocketConnectionstateEnum::
                              android::bluetooth::SocketConnectionstateEnum::
@@ -286,19 +285,8 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
          btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
          btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
      break;
      break;
    case BTSOCK_L2CAP_LE:
    case BTSOCK_L2CAP_LE:
      if (flags & BTSOCK_FLAG_NO_SDP) {
      status = btsock_l2cap_listen(service_name, channel, sock_fd,
        /* Set channel to zero so that it will be assigned */
                                   flags | BTSOCK_FLAG_LE_COC, app_uid);
        channel = 0;
      } else if (channel <= 0) {
        log::error("type BTSOCK_L2CAP_LE: invalid channel={}", channel);
        break;
      }
      flags |= BTSOCK_FLAG_LE_COC;
      log::info(
          "type=BTSOCK_L2CAP_LE, channel=0x{:x}, original=0x{:x}, flags=0x{:x}",
          channel, original_channel, flags);
      status =
          btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
      break;
      break;
    case BTSOCK_SCO:
    case BTSOCK_SCO:
      status = btsock_sco_listen(sock_fd, flags);
      status = btsock_sco_listen(sock_fd, flags);
+12 −2
Original line number Original line Diff line number Diff line
@@ -786,15 +786,25 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name,
                                                  int channel, int* sock_fd,
                                                  int channel, int* sock_fd,
                                                  int flags, char listen,
                                                  int flags, char listen,
                                                  int app_uid) {
                                                  int app_uid) {
  if (!is_inited()) return BT_STATUS_NOT_READY;

  bool is_le_coc = (flags & BTSOCK_FLAG_LE_COC) != 0;
  bool is_le_coc = (flags & BTSOCK_FLAG_LE_COC) != 0;


  if (is_le_coc && listen) {
    if (flags & BTSOCK_FLAG_NO_SDP) {
      /* For LE COC server; set channel to zero so that it will be assigned */
      channel = 0;
    } else if (channel <= 0) {
      log::error("type BTSOCK_L2CAP_LE: invalid channel={}", channel);
      return BT_STATUS_FAIL;
    }
  }

  if (!sock_fd) {
  if (!sock_fd) {
    log::info("Invalid socket descriptor");
    log::info("Invalid socket descriptor");
    return BT_STATUS_PARM_INVALID;
    return BT_STATUS_PARM_INVALID;
  }
  }


  if (!is_inited()) return BT_STATUS_NOT_READY;

  // TODO: This is kind of bad to lock here, but it is needed for the current
  // TODO: This is kind of bad to lock here, but it is needed for the current
  // design.
  // design.
  std::unique_lock<std::mutex> lock(state_lock);
  std::unique_lock<std::mutex> lock(state_lock);