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

Commit 9ea0cd35 authored by Hansong Zhang's avatar Hansong Zhang Committed by Automerger Merge Worker
Browse files

L2cap user dynamic channel: move psm alloc to bta am: a3eca176

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1443306

Change-Id: I5acd29f16654866ec6876ba4e030d8795e94e964
parents 55b86a05 a3eca176
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_set>

#include "avct_api.h"
#include "avdt_api.h"
@@ -51,6 +52,7 @@
using bluetooth::Uuid;

tBTA_JV_CB bta_jv_cb;
std::unordered_set<uint16_t> used_l2cap_classic_dynamic_psm;

static tBTA_JV_PCB* bta_jv_add_rfc_port(tBTA_JV_RFC_CB* p_cb,
                                        tBTA_JV_PCB* p_pcb_open);
@@ -609,6 +611,31 @@ static void bta_jv_set_free_psm(uint16_t psm) {
  }
}

static uint16_t bta_jv_allocate_l2cap_classic_psm() {
  bool done = false;
  uint16_t psm = bta_jv_cb.dyn_psm;

  while (!done) {
    psm += 2;
    if (psm > 0xfeff) {
      psm = 0x1001;
    } else if (psm & 0x0100) {
      /* the upper byte must be even */
      psm += 0x0100;
    }

    /* if psm is in range of reserved BRCM Aware features */
    if ((BRCM_RESERVED_PSM_START <= psm) && (psm <= BRCM_RESERVED_PSM_END))
      continue;

    /* make sure the newlly allocated psm is not used right now */
    if (used_l2cap_classic_dynamic_psm.count(psm) == 0) done = true;
  }
  bta_jv_cb.dyn_psm = psm;

  return (psm);
}

/** Obtain a free SCN (Server Channel Number) (RFCOMM channel or L2CAP PSM) */
void bta_jv_get_channel_id(
    int32_t type /* One of BTA_JV_CONN_TYPE_ */,
@@ -646,7 +673,7 @@ void bta_jv_get_channel_id(
    case BTA_JV_CONN_TYPE_L2CAP:
      psm = bta_jv_get_free_psm();
      if (psm == 0) {
        psm = L2CA_AllocatePSM();
        psm = bta_jv_allocate_l2cap_classic_psm();
        VLOG(2) << __func__ << ": returned PSM=" << loghex(psm);
      }
      break;
+2 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
  for (int i = 0; i < BTA_JV_PM_MAX_NUM; i++) {
    bta_jv_cb.pm_cb[i].handle = BTA_JV_PM_HANDLE_CLEAR;
  }
  bta_jv_cb.dyn_psm = 0xfff;
  used_l2cap_classic_dynamic_psm = {};

  bta_jv_enabled = true;

+4 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ typedef struct {
  uint8_t sdp_active;                          /* see BTA_JV_SDP_ACT_* */
  bluetooth::Uuid uuid;                   /* current uuid of sdp discovery*/
  tBTA_JV_PM_CB pm_cb[BTA_JV_PM_MAX_NUM]; /* PM on a per JV handle bases */

  uint16_t dyn_psm; /* Next dynamic PSM value to try to assign */
} tBTA_JV_CB;

enum {
@@ -136,6 +138,8 @@ enum {
/* JV control block */
extern tBTA_JV_CB bta_jv_cb;

extern std::unordered_set<uint16_t> used_l2cap_classic_dynamic_psm;

/* config struct */
extern tBTA_JV_CFG* p_bta_jv_cfg;

+0 −12
Original line number Diff line number Diff line
@@ -312,18 +312,6 @@ extern uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
 ******************************************************************************/
extern void L2CA_Deregister(uint16_t psm);

/*******************************************************************************
 *
 * Function         L2CA_AllocatePSM
 *
 * Description      Other layers call this function to find an unused PSM for
 *                  L2CAP services.
 *
 * Returns          PSM to use.
 *
 ******************************************************************************/
extern uint16_t L2CA_AllocatePSM(void);

/*******************************************************************************
 *
 * Function         L2CA_AllocateLePSM
+0 −40
Original line number Diff line number Diff line
@@ -182,46 +182,6 @@ void L2CA_Deregister(uint16_t psm) {
  }
}

/*******************************************************************************
 *
 * Function         L2CA_AllocatePSM
 *
 * Description      Other layers call this function to find an unused PSM for
 *                  L2CAP services.
 *
 * Returns          PSM to use.
 *
 ******************************************************************************/
uint16_t L2CA_AllocatePSM(void) {
  if (bluetooth::shim::is_gd_shim_enabled()) {
    return bluetooth::shim::L2CA_AllocatePSM();
  }

  bool done = false;
  uint16_t psm = l2cb.dyn_psm;

  L2CAP_TRACE_API("L2CA_AllocatePSM");
  while (!done) {
    psm += 2;
    if (psm > 0xfeff) {
      psm = 0x1001;
    } else if (psm & 0x0100) {
      /* the upper byte must be even */
      psm += 0x0100;
    }

    /* if psm is in range of reserved BRCM Aware features */
    if ((BRCM_RESERVED_PSM_START <= psm) && (psm <= BRCM_RESERVED_PSM_END))
      continue;

    /* make sure the newlly allocated psm is not used right now */
    if ((l2cu_find_rcb_by_psm(psm)) == NULL) done = true;
  }
  l2cb.dyn_psm = psm;

  return (psm);
}

/*******************************************************************************
 *
 * Function         L2CA_AllocateLePSM
Loading