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

Commit b0060726 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I7eb89883,I93295962,I3ffe28ef,Ice072495,Iba166d9a, ...

* changes:
  Simplify stack/l2cap/l2c_utils::l2cu_create_conn_br_edr
  Simplify stack/l2cap/l2c_link::l2c_link_role_changed
  Remove poor placement for SCN from tACL_CB
  add stack/btm/btm_scn
  Add tBTM_CB::btm_scn[BTM_MAX_SCN_]
  Simplify stack/l2cap/l2c_utils::l2cu_adj_id
  Precisely name tL2C_CB::tL2C_LCB::id
  Remove tL2C_CB::tL2C_LCB::info_rx_bits
  Encapsulate tL2C_CB::tL2C_LCB::link_flush_tout_
  Precisely name tL2C_CB::num_used_lcbs
  Encapsulate tL2C_CB::tL2C_LCB::disc_reason
  Remove set-once-never-execute l2cb.is_flush_active
parents 4eabf24d e551fe4e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ cc_library_static {
        "btm/btm_sco.cc",
        "btm/btm_iso.cc",
        "btm/btm_sec.cc",
        "btm/btm_scn.cc",
        "btu/btu_hcif.cc",
        "btu/btu_task.cc",
        "gap/gap_ble.cc",
+0 −6
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@
#include "types/bt_transport.h"
#include "types/raw_address.h"

#define BTM_MAX_SCN_ 31  // PORT_MAX_RFC_PORTS packages/modules/Bluetooth/system/stack/include/rfcdefs.h

/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
 * function) in response to BTM_SwitchRole call.
 */
@@ -80,11 +78,9 @@ typedef struct {
 ****************************************************/
typedef struct {
 private:
  friend bool BTM_FreeSCN(uint8_t scn);
  friend bool BTM_IsBleConnection(uint16_t hci_handle);
  friend bool BTM_ReadPowerMode(const RawAddress& remote_bda,
                                tBTM_PM_MODE* p_mode);
  friend bool BTM_TryAllocateSCN(uint8_t scn);
  friend bool acl_is_role_switch_allowed();
  friend const RawAddress acl_address_from_handle(uint16_t hci_handle);
  friend int btm_pm_find_acl_ind(const RawAddress& remote_bda);
@@ -104,7 +100,6 @@ typedef struct {
  friend uint16_t acl_get_link_supervision_timeout();
  friend uint16_t acl_get_supported_packet_types();
  friend uint16_t btm_get_acl_disc_reason_code(void);
  friend uint8_t BTM_AllocateSCN(void);
  friend uint8_t acl_get_disconnect_reason();
  friend uint8_t btm_handle_to_acl_index(uint16_t hci_handle);
  friend void BTM_SetDefaultLinkSuperTout(uint16_t timeout);
@@ -153,6 +148,5 @@ typedef struct {
  uint16_t btm_def_link_policy;
  uint16_t btm_def_link_super_tout;
  uint8_t acl_disc_reason;
  uint8_t btm_scn[BTM_MAX_SCN_];
  uint8_t pm_pend_link;
} tACL_CB;
+0 −69
Original line number Diff line number Diff line
@@ -1571,75 +1571,6 @@ void btm_acl_role_changed(uint8_t hci_status, const RawAddress& bd_addr,
#endif
}

/*******************************************************************************
 *
 * Function         BTM_AllocateSCN
 *
 * Description      Look through the Server Channel Numbers for a free one.
 *
 * Returns          Allocated SCN number or 0 if none.
 *
 ******************************************************************************/

uint8_t BTM_AllocateSCN(void) {
  uint8_t x;
  BTM_TRACE_DEBUG("BTM_AllocateSCN");

  // stack reserves scn 1 for HFP, HSP we still do the correct way
  for (x = 1; x < BTM_MAX_SCN; x++) {
    if (!btm_cb.acl_cb_.btm_scn[x]) {
      btm_cb.acl_cb_.btm_scn[x] = true;
      return (x + 1);
    }
  }

  return (0); /* No free ports */
}

/*******************************************************************************
 *
 * Function         BTM_TryAllocateSCN
 *
 * Description      Try to allocate a fixed server channel
 *
 * Returns          Returns true if server channel was available
 *
 ******************************************************************************/

bool BTM_TryAllocateSCN(uint8_t scn) {
  /* Make sure we don't exceed max port range.
   * Stack reserves scn 1 for HFP, HSP we still do the correct way.
   */
  if ((scn >= BTM_MAX_SCN) || (scn == 1)) return false;

  /* check if this port is available */
  if (!btm_cb.acl_cb_.btm_scn[scn - 1]) {
    btm_cb.acl_cb_.btm_scn[scn - 1] = true;
    return true;
  }

  return (false); /* Port was busy */
}

/*******************************************************************************
 *
 * Function         BTM_FreeSCN
 *
 * Description      Free the specified SCN.
 *
 * Returns          true or false
 *
 ******************************************************************************/
bool BTM_FreeSCN(uint8_t scn) {
  BTM_TRACE_DEBUG("BTM_FreeSCN ");
  if (scn <= BTM_MAX_SCN) {
    btm_cb.acl_cb_.btm_scn[scn - 1] = false;
    return (true);
  } else {
    return (false); /* Illegal SCN passed in */
  }
}

/*******************************************************************************
 *
 * Function         btm_set_packet_types
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@
  (BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED | \
   BTM_SEC_LE_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_AUTHED)

#define BTM_MAX_SCN_ 31  // PORT_MAX_RFC_PORTS packages/modules/Bluetooth/system/stack/include/rfcdefs.h

/*
 * Define device configuration structure
*/
@@ -208,6 +210,7 @@ typedef struct {
  tBTM_BT_QUALITY_REPORT_RECEIVER* p_bqr_report_receiver;

  tACL_CB acl_cb_;
  uint8_t btm_scn[BTM_MAX_SCN_];
} tBTM_CB;

/* security action for L2CAP COC channels */
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "btm"

#include <cstdint>
#include "stack/btm/btm_int_types.h"  // tBTM_CB
#include "stack/include/rfcdefs.h"    // BTM_MAX_SCN

extern tBTM_CB btm_cb;

/*******************************************************************************
 *
 * Function         BTM_AllocateSCN
 *
 * Description      Look through the Server Channel Numbers for a free one.
 *
 * Returns          Allocated SCN number or 0 if none.
 *
 ******************************************************************************/
uint8_t BTM_AllocateSCN(void) {
  uint8_t x;
  BTM_TRACE_DEBUG("BTM_AllocateSCN");

  // stack reserves scn 1 for HFP, HSP we still do the correct way
  for (x = 1; x < BTM_MAX_SCN; x++) {
    if (!btm_cb.btm_scn[x]) {
      btm_cb.btm_scn[x] = true;
      return (x + 1);
    }
  }

  return (0); /* No free ports */
}

/*******************************************************************************
 *
 * Function         BTM_TryAllocateSCN
 *
 * Description      Try to allocate a fixed server channel
 *
 * Returns          Returns true if server channel was available
 *
 ******************************************************************************/

bool BTM_TryAllocateSCN(uint8_t scn) {
  /* Make sure we don't exceed max port range.
   * Stack reserves scn 1 for HFP, HSP we still do the correct way.
   */
  if ((scn >= BTM_MAX_SCN) || (scn == 1)) return false;

  /* check if this port is available */
  if (!btm_cb.btm_scn[scn - 1]) {
    btm_cb.btm_scn[scn - 1] = true;
    return true;
  }

  return (false); /* Port was busy */
}

/*******************************************************************************
 *
 * Function         BTM_FreeSCN
 *
 * Description      Free the specified SCN.
 *
 * Returns          true or false
 *
 ******************************************************************************/
bool BTM_FreeSCN(uint8_t scn) {
  BTM_TRACE_DEBUG("BTM_FreeSCN ");
  if (scn <= BTM_MAX_SCN) {
    btm_cb.btm_scn[scn - 1] = false;
    return (true);
  } else {
    return (false); /* Illegal SCN passed in */
  }
}
Loading