Repository navigation
Description
At 0fbc4cf2171a8e77fed3eb89fd510b84439c2218, push_to_gatt() in omi/firmware/omi/src/lib/core/transport.c uses current_mtu - NET_BUFFER_HEADER_SIZE as the audio chunk size, then adds that Omi header back to the notification length. Because current_mtu holds the full ATT MTU, this can construct a value up to MTU bytes, although the ATT notification value limit is MTU minus 3. For example, at MTU 100 a 95-byte audio frame is submitted as a 98-byte notification when only 97 bytes are allowed; the function retries it three times and returns false when the GATT boundary rejects the oversized value. The firmware permits MTUs starting at 100 and CV1 encoded frames up to 160 bytes. This concerns CV1 transport, separate from Omi Glass issue #8452.
A small local patch reserves both headers. I compiled and exercised the actual production function with a host C harness whose GATT fake enforces the documented size limit: the baseline fails 5 of 12 cases, and the patch passes all 12. Cases cover boundary sizes, complete payload reconstruction, sequence wrap, transient retries, terminal failure, and transmit-slot balance. This is host-side behavioral evidence, not an NCS firmware build, real Zephyr-stack run, radio/device test, or completed repository preflight. The patch remains uncommitted.
@josancamon19 — Following your contribution guide, would you sponsor US$25 via PayPal after acceptance and merge for a focused fix with regression coverage? Please confirm whether the scope is wanted, whether someone is already addressing it, and whether this payment route is available. No existing bounty or payment obligation is assumed. AI disclosure: investigation, patch, and tests were prepared by OpenAI Codex for rakhimabdulkhanov-m. Payment details would be provided privately only after agreement.
References: Zephyr notification value limit, tested transport source.
Local candidate patch and reproducible host test
diff --git a/omi/firmware/omi/src/lib/core/transport.c b/omi/firmware/omi/src/lib/core/transport.c
index 3196ce0..dd26384 100644
--- a/omi/firmware/omi/src/lib/core/transport.c
+++ b/omi/firmware/omi/src/lib/core/transport.c
@@ -971,6 +971,7 @@ static int ensure_local_ble_identity(void)
//
#define NET_BUFFER_HEADER_SIZE 3
+#define ATT_NOTIFICATION_HEADER_SIZE 3 // ATT opcode (1 byte) and attribute handle (2 bytes)
#define RING_BUFFER_HEADER_SIZE 2
static uint8_t tx_queue[NETWORK_RING_BUF_SIZE * (CODEC_OUTPUT_MAX_BYTES + RING_BUFFER_HEADER_SIZE)];
static uint8_t tx_buffer[CODEC_OUTPUT_MAX_BYTES + RING_BUFFER_HEADER_SIZE];
@@ -1072,7 +1073,8 @@ static bool push_to_gatt(struct bt_conn *conn)
const int max_retries = 3;
while (offset < tx_buffer_size) {
- uint32_t packet_size = MIN(current_mtu - NET_BUFFER_HEADER_SIZE, tx_buffer_size - offset);
+ uint32_t packet_size =
+ MIN(current_mtu - ATT_NOTIFICATION_HEADER_SIZE - NET_BUFFER_HEADER_SIZE, tx_buffer_size - offset);
// Block until a throttle slot is available. This preserves every audio
// packet while still guaranteeing AUDIO_TX_RESERVED_SLOTS remain freeSave the script below as check_cv1_mtu.py, then run python check_cv1_mtu.py /path/to/transport.c. Requires Python 3 and cc. The supplied source function is compiled unchanged; GATT and semaphore dependencies are test fakes. Baseline: 5/12 cases fail, exit 1. Patched: 12/12 pass, exit 0. Tested with GCC 13.3.0 on Linux x86_64. Callback completion is immediate; radio concurrency is not tested.
"""Compile and exercise the real push_to_gatt function with a strict GATT fake.
Usage: python check_cv1_mtu.py /path/to/transport.c
Requires Python 3 and a C compiler (cc). No BLE hardware or Zephyr SDK needed.
This checks packet construction and retry/slot behavior, not radio integration.
"""
from pathlib import Path
import re
import subprocess
import sys
import tempfile
PREFIX = r'''
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#define MIN(a,b) ((uint32_t)(a)<(uint32_t)(b)?(uint32_t)(a):(uint32_t)(b))
#define K_FOREVER 0
#define K_MSEC(x) (x)
#define LOG_DBG(...) ((void)0)
#define LOG_ERR(...) ((void)0)
struct bt_conn { int placeholder; };
struct bt_gatt_notify_params {
int *attr;
const void *data;
uint16_t len;
void (*func)(struct bt_conn *, void *);
void *user_data;
};
static struct { int attrs[2]; } audio_service;
static uint8_t tx_buffer[162], pusher_temp_data[517], received[160];
static uint32_t tx_buffer_size;
static uint16_t current_mtu, packet_next_index, initial_sequence;
static int audio_tx_sem, calls, failures_left, accepted, received_size;
static void k_sem_take(int *s, int timeout) { (void)timeout; assert(*s > 0); --*s; }
static void k_sem_give(int *s) { ++*s; }
static void k_sleep(int delay) { (void)delay; }
static void on_audio_tx_done(struct bt_conn *conn, void *user_data) {
(void)conn; (void)user_data; k_sem_give(&audio_tx_sem);
}
static int bt_gatt_notify_cb(struct bt_conn *conn, struct bt_gatt_notify_params *p) {
++calls;
/* ATT notification value = MTU minus opcode (1) and handle (2). */
if (p->len > current_mtu - 3) return -EMSGSIZE;
if (failures_left > 0) { --failures_left; return -ENOMEM; }
const uint8_t *bytes = p->data;
assert(p->len > NET_BUFFER_HEADER_SIZE);
assert((uint16_t)(bytes[0] | (bytes[1] << 8)) == (uint16_t)(initial_sequence + accepted));
assert(bytes[2] == accepted);
assert((size_t)(received_size + p->len - NET_BUFFER_HEADER_SIZE) <= sizeof(received));
memcpy(received + received_size, bytes + NET_BUFFER_HEADER_SIZE, p->len - NET_BUFFER_HEADER_SIZE);
received_size += p->len - NET_BUFFER_HEADER_SIZE;
++accepted;
p->func(conn, p->user_data);
return 0;
}
'''
SUFFIX = r'''
static int check_case(int mtu, int size, int transient_failures, uint16_t sequence) {
current_mtu = mtu;
tx_buffer_size = size;
initial_sequence = packet_next_index = sequence;
calls = accepted = received_size = 0;
failures_left = transient_failures;
audio_tx_sem = 8;
memset(received, 0, sizeof(received));
for (int i = 0; i < size; ++i) tx_buffer[i + RING_BUFFER_HEADER_SIZE] = (uint8_t)(i * 17 + 3);
struct bt_conn conn = {0};
bool result = push_to_gatt(&conn);
bool expected_success = transient_failures < 3 || size == 0;
int chunks = size == 0 ? 0 : (size + (mtu - 6) - 1) / (mtu - 6);
bool ok = result == expected_success && audio_tx_sem == 8;
if (expected_success) {
ok = ok && received_size == size && accepted == chunks;
ok = ok && memcmp(received, tx_buffer + RING_BUFFER_HEADER_SIZE, size) == 0;
ok = ok && calls == chunks + (size ? transient_failures : 0);
} else {
ok = ok && accepted == 0 && calls == 3;
}
printf("%s mtu=%d audio=%d retries=%d start=%u result=%d delivered=%d notifications=%d calls=%d slots=%d\n",
ok ? "PASS" : "FAIL", mtu, size, transient_failures, sequence,
result, received_size, accepted, calls, audio_tx_sem);
return !ok;
}
int main(void) {
int failed = 0;
failed += check_case(100, 0, 0, 0);
failed += check_case(100, 80, 0, 0);
failed += check_case(100, 94, 0, 0);
failed += check_case(100, 95, 0, 0);
failed += check_case(100, 102, 0, 0);
failed += check_case(100, 160, 0, 0);
failed += check_case(128, 122, 0, 0);
failed += check_case(128, 123, 0, 0);
failed += check_case(185, 160, 0, 0);
failed += check_case(517, 160, 0, 0);
failed += check_case(100, 160, 2, 65535);
failed += check_case(100, 80, 3, 0);
printf("%d of 12 cases failed\n", failed);
return failed ? 1 : 0;
}
'''
def main():
source = Path(sys.argv[1]).read_text()
start = source.index("static bool push_to_gatt(struct bt_conn *conn)")
end = source.index("\n#define OPUS_PREFIX_LENGTH", start)
function = source[start:end]
constants = "\n".join(re.findall(
r"^#define (?:NET_BUFFER_HEADER_SIZE|ATT_NOTIFICATION_HEADER_SIZE|RING_BUFFER_HEADER_SIZE)\b[^\n]*",
source,
flags=re.MULTILINE,
))
with tempfile.TemporaryDirectory(prefix="omi-mtu-check-") as directory:
c_file = Path(directory) / "check.c"
executable = Path(directory) / "check"
c_file.write_text(constants + "\n" + PREFIX + function + SUFFIX)
subprocess.run(["cc", "-std=c11", "-Wall", "-Wextra", "-Werror", str(c_file), "-o", str(executable)], check=True)
return subprocess.run([str(executable)], check=False).returncode
if __name__ == "__main__":
raise SystemExit(main())Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsIn review
Activity
bdzialo commentedon Sep 9, 2026
I'm interested in taking this contribution. Before I start implementation, could you please confirm that the proposed US$25 bounty via the documented private PayPal process is approved for this scope, and that AI-assisted work with disclosed assistance is eligible? I would keep the fix focused on the ATT notification sizing issue and include the regression coverage described above. No payment details would be posted here; they would only be provided privately if the contribution is accepted and the project requests them.
aryanorastar commentedon Nov 5, 2026
Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏
fix(firmware): bound audio notification chunk size to ATT MTU limit