Long read to the server returns MTU size response
- Dominant language
- C
- Stars
- 893
- Forks
- 512
- Avg merge
- 13d 31m
- Merged PRs (30d)
- 7
Description
I'm trying to use long read on a characteristics (max size is 500 bytes), with MTU size of 180.
The issue is, that on server side, when BLE_GATT_ACCESS_OP_READ_CHR event is called and I call os_mbuf_append() function (as per example), the server only returns MTU size to the client, even though the long read was called.
I got somewhat working results by calling multiple os_mbuf_appendfrom() where I used MTU size offset for each call (to get the all 500 bytes), but this seemed very sketchy to me. Or is this perhaps the only way to do this?
I could not find any info on long reads with nimble in examples and on the internet, so I'm hoping somebody here can help me.
EDIT: added sample code:
Client does this:
rc = ble_gattc_read_long(connection_handle, chr->chr.val_handle, 0, ble_spp_on_read, NULL);
ble_spp_on_read just prints out the received buffer.
From server event BLE_GATT_ACCESS_OP_READ_CHR
uint16_t test_size = 500;
uint8_t rsp[test_size];
// set test buffer
for(int i = 0; i < test_size; i++) {
if(i > 180) rsp[i] = 2;
else rsp[i] = 1;
printf("%d ", rsp[i]);
}
printf("\n");
struct os_mbuf *txom;
txom= ble_hs_mbuf_from_flat(rsp, test_size);
ret = os_mbuf_append(ctxt->om, txom, test_size);
if(ret == BLE_ATT_ERR_INSUFFICIENT_RES || ret != ESP_OK)
ESP_LOGE(tag, "Error responding: %d", ret);
Thanks!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the BLE_GATT_ACCESS_OP_READ_CHR callback and the client’s ble_gattc_read_long call, then inspect how ctxt->om is populated and consumed across requests. Compare the os_mbuf_append and os_mbuf_appendfrom usage shown in the report. Done means a 500-byte characteristic can be read through the long-read procedure with MTU-sized responses as needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100