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

Commit 01f0a97d authored by Kihong Seong's avatar Kihong Seong Committed by Gerrit Code Review
Browse files

Merge "Change max attribute length from 600 bytes to 512 bytes" into main

parents 2f402649 26e30a7d
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
@@ -32,6 +32,7 @@
#include <base/threading/thread.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>

#include <string>

@@ -418,7 +419,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
@@ -442,7 +443,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
@@ -469,7 +470,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);
@@ -504,7 +505,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,
@@ -534,7 +535,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
@@ -29,6 +29,7 @@
#include <base/functional/bind.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>
@@ -398,7 +399,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
@@ -2790,7 +2790,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