kopia lustrzana https://github.com/espressif/esp-idf
component/bt : fix BLUFI bug with small MTU size
rodzic
02460ff864
commit
2c334b46e0
|
@ -177,6 +177,10 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
|||
blufi_env.prepare_buf = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
case BTA_GATTS_MTU_EVT:
|
||||
LOG_DEBUG("MTU size %d\n", p_data->req_data.p_data->mtu);
|
||||
blufi_env.frag_size = p_data->req_data.p_data->mtu - BLUFI_MTU_RESERVED_SIZE;
|
||||
break;
|
||||
case BTA_GATTS_CONF_EVT:
|
||||
LOG_DEBUG("CONIRM EVT\n");
|
||||
|
@ -294,6 +298,7 @@ static tGATT_STATUS btc_blufi_profile_init(void)
|
|||
|
||||
memset(&blufi_env, 0x0, sizeof(blufi_env));
|
||||
blufi_env.cbs = store_p; /* if set callback prior, restore the point */
|
||||
blufi_env.frag_size = BLUFI_FRAG_DATA_DEFAULT_LEN;
|
||||
|
||||
/* register the BLUFI profile to the BTA_GATTS module*/
|
||||
BTA_GATTS_AppRegister(&blufi_app_uuid, blufi_profile_cb);
|
||||
|
@ -406,16 +411,16 @@ void btc_blufi_send_encap(uint8_t type, uint8_t *data, int total_data_len)
|
|||
int ret;
|
||||
|
||||
while (remain_len > 0) {
|
||||
if (remain_len > BLUFI_FRAG_DATA_MAX_LEN) {
|
||||
hdr = GKI_getbuf(sizeof(struct blufi_hdr) + 2 + BLUFI_FRAG_DATA_MAX_LEN + 2);
|
||||
if (remain_len > blufi_env.frag_size) {
|
||||
hdr = GKI_getbuf(sizeof(struct blufi_hdr) + 2 + blufi_env.frag_size + 2);
|
||||
if (hdr == NULL) {
|
||||
LOG_ERROR("%s no mem\n", __func__);
|
||||
return;
|
||||
}
|
||||
hdr->fc = 0x0;
|
||||
hdr->data_len = BLUFI_FRAG_DATA_MAX_LEN + 2;
|
||||
hdr->data_len = blufi_env.frag_size + 2;
|
||||
*(uint16_t *)hdr->data = remain_len;
|
||||
memcpy(hdr->data + 2, &data[total_data_len - remain_len], BLUFI_FRAG_DATA_MAX_LEN); //copy first, easy for check sum
|
||||
memcpy(hdr->data + 2, &data[total_data_len - remain_len], blufi_env.frag_size); //copy first, easy for check sum
|
||||
hdr->fc |= BLUFI_FC_FRAG;
|
||||
} else {
|
||||
hdr = GKI_getbuf(sizeof(struct blufi_hdr) + remain_len + 2);
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct {
|
|||
BD_ADDR remote_bda;
|
||||
UINT32 trans_id;
|
||||
UINT8 congest;
|
||||
UINT16 frag_size;
|
||||
#define BLUFI_PREPAIR_BUF_MAX_SIZE 1024
|
||||
uint8_t *prepare_buf;
|
||||
int prepare_len;
|
||||
|
@ -160,7 +161,9 @@ typedef struct blufi_frag_hdr blufi_frag_hdr_t;
|
|||
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
|
||||
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
|
||||
|
||||
#define BLUFI_FRAG_DATA_MAX_LEN 50
|
||||
/* BLUFI HEADER + TOTAL(REMAIN) LENGTH + CRC + L2CAP RESERVED */
|
||||
#define BLUFI_MTU_RESERVED_SIZE (sizeof(struct blufi_hdr) + 2 + 2 + 3)
|
||||
#define BLUFI_FRAG_DATA_DEFAULT_LEN (GATT_DEF_BLE_MTU_SIZE - BLUFI_MTU_RESERVED_SIZE)
|
||||
|
||||
//function declare
|
||||
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len);
|
||||
|
|
Ładowanie…
Reference in New Issue