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

Commit f4cbadec authored by Pomai Ahlo's avatar Pomai Ahlo
Browse files

Allow SCN 30 to be freed

BTA_FreeSCN currently treats SCN 30 as invalid.  It is valid and should
be able to be freed.

Bug: 372923869
Bug: 372922664
Test: atest BtaRfcommScnTest
Flag: com::android::bluetooth::flags::allow_free_last_scn
Change-Id: I2a1bdf439ae559ebdc7e24ab719636d205bfa09a
parent eca2c8ea
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define LOG_TAG "bta"

#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <cstdint>

@@ -64,7 +65,7 @@ uint8_t BTA_AllocateSCN(void) {
      return i + 1;  // allocated scn is index + 1
    }
  }
  log::debug("Unable to allocate an scn");
  log::warn("Unable to allocate an scn");
  return 0; /* No free ports */
}

@@ -109,12 +110,21 @@ bool BTA_FreeSCN(uint8_t scn) {
  /* Since this isn't used by HFP, this function will only free valid SCNs
   * that aren't reserved for HFP, which is range [2, RFCOMM_MAX_SCN].
   */
  if (scn < RFCOMM_MAX_SCN && scn > 1) {

  if (com::android::bluetooth::flags::allow_free_last_scn()) {
    if (scn <= RFCOMM_MAX_SCN && scn > 1) {
      bta_jv_cb.scn_in_use[scn - 1] = false;
      log::debug("Freed SCN: {}", scn);
      return true;
    }
  } else {
    if (scn < RFCOMM_MAX_SCN && scn > 1) {
      bta_jv_cb.scn_in_use[scn - 1] = false;
      log::debug("Freed SCN: {}", scn);
      return true;
    }
  }

  log::warn("Invalid SCN: {}", scn);
  return false; /* Illegal SCN passed in */
}
}