-
Notifications
You must be signed in to change notification settings - Fork 33
Bugfix/fix bluetooth bt tool hfp ag moudle cb change to const #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Bugfix/fix bluetooth bt tool hfp ag moudle cb change to const #444
Conversation
…k to const for reduce the ram size. bug: v/84934 Rootcause: To reduce RAM resource consumption, the `adv_callback` in the ble impl module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…re_gattc_cbs to const for reduce the ram size. bug: v/84935 Rootcause: To reduce RAM resource consumption, the `s_feature_gattc_cbs` in the gatt feature module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…v_callback to const for reduce the ram size. bug: v/84941 Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb` in the socket advertiser module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…back to const for reduce the ram size. bug: v/84944 Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb` in the socket scan module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…ket_cb to const for reduce the ram size. bug: v/84945 Rootcause: To reduce RAM resource consumption, the `g_spp_socket_cb` in the socket spp module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size. bug:v/84946 Rootcause: To reduce RAM resource consumption, the `deviceInterface` in the hid device service module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
… for reduce the ram size. bug:v/84947 Rootcause: To reduce RAM resource consumption, the `sppInterface` in the spp service module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size. bug:v/84950 Rootcause: To reduce RAM resource consumption, the `stream_ops` in the sal a2dp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…e to const for reduce the ram size. bug:v/84951 Rootcause: To reduce RAM resource consumption, the `g_conn_cbs`, `g_setting_cbs`, `g_conn_auth_info_cbs`and `g_br_discovery_cb`, in the sal adapter interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…dule to const for reduce the ram size. bug:v/84952 Rootcause: To reduce RAM resource consumption, the `g_conn_auth_info_cbs`, `g_conn_cbs`, and `g_setting_cbs` in the sal adapter interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84953 Rootcause: To reduce RAM resource consumption, the `avrcp_tg_cbks`, in the sal avrcp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… to const for reduce the ram size. bug:v/84954 Rootcause: To reduce RAM resource consumption, the `g_hfp_ag_cb`, in the sal hfp ag interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…e to const for reduce the ram size. bug:v/84956 Rootcause: To reduce RAM resource consumption, the `hf_callbacks`, in the sal hfp hf interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size. bug:v/84957 Rootcause: To reduce RAM resource consumption, the `hid_attrs_template` and `hid_callback`, in the sal hid device interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size. bug:v/84958 Rootcause: To reduce RAM resource consumption, the `spp_attrs_template` and `g_rfcomm_ops`, in the sal spp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84959 Rootcause: To reduce RAM resource consumption, the `g_a2dp_tables`, in the bt_tools a2dp source module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… for reduce the ram size. bug:v/84960 Rootcause: To reduce RAM resource consumption, the `adv_options`,a dv_stop_options, `g_adv_tables` and `adv_callback` in the bt_tools adv module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… const for reduce the ram size. bug:v/84961 Rootcause: To reduce RAM resource consumption, the `adv_options`, `adv_stop_options`, `g_adv_async_tables` and `adv_callback` in the bt_tools async adv module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… const for reduce the ram size. bug:v/84961 Rootcause: To reduce RAM resource consumption, the `le_conn_options`, `g_set_cmd_tables`, `g_get_cmd_tables` and `g_pair_cmd_tables` in the bt_tools async gap module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…odule to const for reduce the ram size. bug:v/84966 Rootcause: To reduce RAM resource consumption, the `g_gattc_async_tables`, `gattc_cbs`, in the bt_tools async gatt client module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… for reduce the ram size. bug:v/84967 Rootcause: To reduce RAM resource consumption, the `g_log_async_tables`, in the bt_tools log module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…t for reduce the ram size. bug:v/84968 Rootcause: To reduce RAM resource consumption, the `scan_options`, in the bt_tools scan module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… reduce the ram size. bug:v/84969 Rootcause: To reduce RAM resource consumption, the `le_conn_options`, `g_cmd_tables`, `g_set_cmd_tables` and `g_pair_cmd_tables` in the bt_tools module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size.
bug:v/84970
Rootcause: To reduce RAM resource consumption, the `g_gattc_tables`,
`gattc_cbs`,
in the bt_tools gatt client module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.
Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84971 Rootcause: To reduce RAM resource consumption, the `s_dis_attr_db`, `s_bas_attr_db`, `s_iot_attr_db`, `g_gatts_tables` in the bt_tools gatt server module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…nst for reduce the ram size. bug:v/84972 Rootcause: To reduce RAM resource consumption, the `g_hfp_ag_tables`, in the bt_tools hfp ag module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR optimizes RAM usage by converting static data structures in the Bluetooth tools and service layers to const, enabling them to be stored in Flash memory rather than RAM. The PR addresses bug v/84972 by systematically adding the const modifier to command tables, callback structures, and GATT attribute databases across the codebase.
Changes:
- Marked static callback structures and command tables as
constacross tools/ and service/ directories - Added explicit casts when passing const pointers to APIs that don't have const-correct signatures
- Added forward declarations in sal_adapter_le_interface.c for organizational purposes
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/hfp_ag.c | Made g_hfp_ag_tables const with cast at call site |
| tools/gatt_server.c | Made attribute databases and command tables const with casts |
| tools/gatt_client.c | Made g_gattc_tables and gattc_cbs const with casts |
| tools/bt_tools.c | Made multiple command tables and option arrays const with casts |
| tools/async/scan.c | Made scan_options and g_scanner_async_tables const with cast |
| tools/async/log.c | Made g_log_async_tables const with cast |
| tools/async/gatt_client.c | Made g_gattc_async_tables and gattc_cbs const with casts |
| tools/async/gap.c | Made multiple command and option tables const with casts |
| tools/async/adv.c | Made advertising tables and callbacks const with casts |
| tools/adv.c | Made advertising tables and callbacks const with casts |
| tools/a2dp_source.c | Made g_a2dp_tables const with cast |
| service/stacks/zephyr/sal_spp_interface.c | Made SDP attributes and RFCOMM ops const with casts |
| service/stacks/zephyr/sal_hid_device_interface.c | Made HID attributes and callbacks const with casts |
| service/stacks/zephyr/sal_hfp_hf_interface.c | Made HFP HF callbacks const with cast |
| service/stacks/zephyr/sal_hfp_ag_interface.c | Made HFP AG callbacks const with cast |
| service/stacks/zephyr/sal_avrcp_interface.c | Made AVRCP target callbacks const |
| service/stacks/zephyr/sal_adapter_le_interface.c | Made LE connection and auth callbacks const with casts, added forward declarations |
| service/stacks/zephyr/sal_adapter_interface.c | Made BR/EDR adapter callbacks const with casts |
| service/stacks/zephyr/sal_a2dp_interface.c | Made A2DP codec config and callbacks const with casts |
| service/profiles/spp/spp_service.c | Made SPP interface const |
| service/profiles/hid/hid_device_service.c | Made HID device interface const |
| service/ipc/socket/src/bt_socket_spp.c | Made SPP socket callbacks const with cast |
| service/ipc/socket/src/bt_socket_scan.c | Made scanner socket callbacks const with cast |
| service/ipc/socket/src/bt_socket_advertiser.c | Made advertiser socket callbacks const with cast |
| framework/btwrap/async/bt_gatt_feature.c | Made feature GATT client callbacks const with cast |
| feature/feature_async/src/bluetooth_ble_impl.c | Made advertiser callbacks and GATT client callbacks const with casts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (argc > 0) | ||
| ret = execute_command_in_table(handle, g_hfp_ag_tables, ARRAY_SIZE(g_hfp_ag_tables), argc, argv); | ||
| ret = execute_command_in_table(handle, (bt_command_t *)g_hfp_ag_tables, ARRAY_SIZE(g_hfp_ag_tables), argc, argv); |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting away const is a workaround that indicates the function signature for execute_command_in_table should accept a const pointer. Since the function only reads from the table (iterating through it to find matching commands), the parameter should be declared as const bt_command_t*. This would eliminate the need for this cast and improve type safety throughout the codebase.
| ret = execute_command_in_table(handle, (bt_command_t *)g_hfp_ag_tables, ARRAY_SIZE(g_hfp_ag_tables), argc, argv); | |
| ret = execute_command_in_table(handle, g_hfp_ag_tables, ARRAY_SIZE(g_hfp_ag_tables), argc, argv); |
| } | ||
|
|
||
| if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, &gattc_cbs) != BT_STATUS_SUCCESS) | ||
| if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, (gattc_callbacks_t *)&gattc_cbs) != BT_STATUS_SUCCESS) |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting away const is a workaround that indicates the bt_gattc_create_connect function signature should accept a const pointer for callbacks. Since callbacks are only stored and invoked (not modified), the API should be updated to accept const gattc_callbacks_t*. This pattern appears in the binder code where callbacks are already stored as const, suggesting this is the intended design.
| } | ||
|
|
||
| spp_conn->rfcomm_dlc.ops = &g_rfcomm_ops; | ||
| spp_conn->rfcomm_dlc.ops = (struct bt_rfcomm_dlc_ops *)&g_rfcomm_ops; |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting away const to assign to a Zephyr API structure field. This is a pragmatic workaround since the underlying Zephyr bt_rfcomm_dlc structure doesn't use const-qualified pointers for ops. While the callbacks are not modified in practice, this cast technically invokes undefined behavior per the C standard if the underlying library were to modify these callbacks. Consider working with the Zephyr project to add const-correctness to their API signatures.
Memory Optimization: Change the bluetooth bt_tool hfp ag module to const for reduce the ram size.
bug:v/84972
Rootcause: To reduce RAM resource consumption, the
g_hfp_ag_tables,in the bt_tools hfp ag module must be marked with the
constmodifier.This ensures it is compiled and linked into Flash memory instead of RAM.