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

Commit 26e30a7d authored by Kihong Seong's avatar Kihong Seong
Browse files

Change max attribute length from 600 bytes to 512 bytes

This change removes BTGATT_MAX_ATTR_LEN, defined in bt_gatt_client.h as
600. It is causing problems and differs from the correct max attribute
length in Android, which is 512 bytes. A new correct max attribute
length is defined in bt_gatt_types.h and used instead. In a follow up
CL, another GATT_MAX_ATTR_LEN defined in gatt_api.h will be replaced
with the new one added in this CL.

Bug: 301025186
Test: m com.android.btservices
Change-Id: I0779f63202163fbae282dcd50ce76b53611cfeda
parent ce7714ba
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "com_android_bluetooth.h"
#include "gd/common/init_flags.h"
#include "hardware/bt_gatt.h"
#include "hardware/bt_gatt_types.h"
#include "rust/cxx.h"
#include "rust/src/gatt/ffi/gatt_shim.h"
#include "src/gatt/ffi.rs.h"
@@ -2113,10 +2114,10 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject /* object */,
  response.attr_value.len = 0;

  if (val != NULL) {
    if (env->GetArrayLength(val) < BTGATT_MAX_ATTR_LEN) {
    if (env->GetArrayLength(val) < GATT_MAX_ATTR_LEN) {
      response.attr_value.len = (uint16_t)env->GetArrayLength(val);
    } else {
      response.attr_value.len = BTGATT_MAX_ATTR_LEN;
      response.attr_value.len = GATT_MAX_ATTR_LEN;
    }

    jbyte* array = env->GetByteArrayElements(val, 0);
+6 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <errno.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>

#include <string>

@@ -420,7 +421,7 @@ void read_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
  params->status = status;
  params->handle = handle;
  params->value.len = len;
  CHECK(len <= BTGATT_MAX_ATTR_LEN);
  CHECK(len <= GATT_MAX_ATTR_LEN);
  if (len > 0) memcpy(params->value.value, value, len);

  // clang-tidy analyzer complains about |params| is leaked.  It doesn't know
@@ -444,7 +445,7 @@ void read_using_char_uuid_cb(uint16_t conn_id, tGATT_STATUS status,
  params->status = status;
  params->handle = handle;
  params->value.len = len;
  CHECK(len <= BTGATT_MAX_ATTR_LEN);
  CHECK(len <= GATT_MAX_ATTR_LEN);
  if (len > 0) memcpy(params->value.value, value, len);

  // clang-tidy analyzer complains about |params| is leaked.  It doesn't know
@@ -471,7 +472,7 @@ void read_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle,
  params.status = status;
  params.handle = handle;
  params.value.len = len;
  CHECK(len <= BTGATT_MAX_ATTR_LEN);
  CHECK(len <= GATT_MAX_ATTR_LEN);
  if (len > 0) memcpy(params.value.value, value, len);

  CLI_CBACK_IN_JNI(read_descriptor_cb, conn_id, status, params);
@@ -506,7 +507,7 @@ static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle,

  std::vector<uint8_t> value(val, val + len);

  if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN);
  if (value.size() > GATT_MAX_ATTR_LEN) value.resize(GATT_MAX_ATTR_LEN);

  return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, conn_id, handle,
                               write_type, std::move(value), auth_req,
@@ -536,7 +537,7 @@ static bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle,

  std::vector<uint8_t> value(val, val + len);

  if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN);
  if (value.size() > GATT_MAX_ATTR_LEN) value.resize(GATT_MAX_ATTR_LEN);

  return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, conn_id, handle,
                               std::move(value), auth_req, write_descr_cb,
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <errno.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -403,7 +404,7 @@ static bt_status_t btif_gatts_send_indication(int server_if,
                                              size_t length) {
  CHECK_BTGATT_INIT();

  if (length > BTGATT_MAX_ATTR_LEN) length = BTGATT_MAX_ATTR_LEN;
  if (length > GATT_MAX_ATTR_LEN) length = GATT_MAX_ATTR_LEN;

  return do_in_jni_thread(Bind(&BTA_GATTS_HandleValueIndication, conn_id,
                               attribute_handle,
+1 −1
Original line number Diff line number Diff line
@@ -2793,7 +2793,7 @@ impl IBluetoothGatt for BluetoothGatt {
            let handle = self.server_context_map.get_request_handle_from_id(request_id)?;
            let len = value.len() as u16;

            let data: [u8; 600] = array_utils::to_sized_array(&value);
            let data: [u8; 512] = array_utils::to_sized_array(&value);

            self.gatt.as_ref().unwrap().lock().unwrap().server.send_response(
                conn_id,
+2 −8
Original line number Diff line number Diff line
@@ -26,15 +26,9 @@

__BEGIN_DECLS

/**
 * Buffer sizes for maximum attribute length and maximum read/write
 * operation buffer size.
 */
#define BTGATT_MAX_ATTR_LEN 600

/** Buffer type for unformatted reads/writes */
typedef struct {
  uint8_t value[BTGATT_MAX_ATTR_LEN];
  uint8_t value[GATT_MAX_ATTR_LEN];
  uint16_t len;
} btgatt_unformatted_value_t;

@@ -56,7 +50,7 @@ typedef struct {

/** Attribute change notification parameters */
typedef struct {
  uint8_t value[BTGATT_MAX_ATTR_LEN];
  uint8_t value[GATT_MAX_ATTR_LEN];
  RawAddress bda;
  uint16_t handle;
  uint16_t len;
Loading