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

Commit cb7aef9f authored by Hsin-chen Chuang's avatar Hsin-chen Chuang Committed by Gerrit Code Review
Browse files

Merge "AG: Parse BRSF as uint32_t and discard reserved bits" into main

parents 425a8545 ce55e624
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@

#include "bta/ag/bta_ag_at.h"

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

#include <cstdint>
#include <cstdlib>

#include "bta/ag/bta_ag_int.h"
#include "bta/include/utl.h"
@@ -138,7 +140,31 @@ void bta_ag_process_at(tBTA_AG_AT_CB* p_cb, char* p_end) {
      /* if it's a set integer check max, min range */
      if (arg_type == BTA_AG_AT_SET &&
          p_cb->p_at_tbl[idx].fmt == BTA_AG_AT_INT) {
#if TARGET_FLOSS
        if (true)
#else
        if (IS_FLAG_ENABLED(bta_ag_cmd_brsf_allow_uint32))
#endif
        {
          if (p_cb->p_at_tbl[idx].command_id == BTA_AG_LOCAL_EVT_BRSF) {
            // Per HFP v1.9 BRSF could be 32-bit integer and we should ignore
            // all reserved bits rather than responding ERROR.
            long long int_arg_ll = std::atoll(p_arg);
            if (int_arg_ll >= (1ll << 32) || int_arg_ll < 0) int_arg_ll = -1;

            // Ignore reserved bits. 0xfff because there are 12 defined bits.
            if (int_arg_ll > 0 && (int_arg_ll & (~0xfffll))) {
              log::warn("BRSF: reserved bit is set: 0x{:x}", int_arg_ll);
              int_arg_ll &= 0xfffll;
            }

            int_arg = static_cast<int16_t>(int_arg_ll);
          } else {
            int_arg = utl_str2int(p_arg);
          }
        } else {
          int_arg = utl_str2int(p_arg);
        }
        if (int_arg < (int16_t)p_cb->p_at_tbl[idx].min ||
            int_arg > (int16_t)p_cb->p_at_tbl[idx].max) {
          /* arg out of range; error */
+0 −11
Original line number Diff line number Diff line
@@ -63,17 +63,6 @@ using namespace bluetooth;

#define COLON_IDX_4_VGSVGM 4

/* Local events which will not trigger a higher layer callback */
enum {
  BTA_AG_LOCAL_EVT_FIRST = 0x100,
  BTA_AG_LOCAL_EVT_CCWA,
  BTA_AG_LOCAL_EVT_CLIP,
  BTA_AG_LOCAL_EVT_CMER,
  BTA_AG_LOCAL_EVT_BRSF,
  BTA_AG_LOCAL_EVT_CMEE,
  BTA_AG_LOCAL_EVT_BCC,
};

/* AT command interpreter table for HSP */
static const tBTA_AG_AT_CMD bta_ag_hsp_cmd[] = {
    {"+CKPD", BTA_AG_AT_CKPD_EVT, BTA_AG_AT_SET, BTA_AG_AT_INT, 200, 200},
+11 −0
Original line number Diff line number Diff line
@@ -94,6 +94,17 @@ enum {
  BTA_AG_MAX_EVT,
};

/* Local events which will not trigger a higher layer callback */
enum {
  BTA_AG_LOCAL_EVT_FIRST = 0x100,
  BTA_AG_LOCAL_EVT_CCWA,
  BTA_AG_LOCAL_EVT_CLIP,
  BTA_AG_LOCAL_EVT_CMER,
  BTA_AG_LOCAL_EVT_BRSF,
  BTA_AG_LOCAL_EVT_CMEE,
  BTA_AG_LOCAL_EVT_BCC,
};

/* Actions to perform after a SCO event */
enum {
  BTA_AG_POST_SCO_NONE,      /* no action */