-
Notifications
You must be signed in to change notification settings - Fork 33
Bugfix/fix bluetooth bt tool hfp hf moudle cb change to const #445
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 hf moudle cb change to const #445
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>
…nst for reduce the ram size. bug:v/84973 Rootcause: To reduce RAM resource consumption, the `g_hfp_tables`, in the bt_tools hfp hf 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 memory usage by marking static command tables, option structures, callback structures, and GATT attribute databases as const in Bluetooth tool and service modules. By making these read-only data structures const, they are placed in Flash memory instead of RAM, reducing RAM consumption across the Bluetooth stack.
Changes:
- Command tables and option structures in tools modules converted to const with necessary casts when passed to APIs
- Callback structures in service stack, profile, IPC, and framework modules converted to const with casts at registration points
- GATT attribute database structures in gatt_server.c converted to const with appropriate casts
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/hfp_hf.c | Converts g_hfp_tables command table to const with cast at execute_command_in_table call |
| tools/hfp_ag.c | Converts g_hfp_ag_tables command table to const with cast at execute_command_in_table call |
| tools/gatt_server.c | Converts GATT attribute database arrays (s_dis_attr_db, s_bas_attr_db, s_iot_attr_db) and g_gatts_tables to const with casts |
| tools/gatt_client.c | Converts g_gattc_tables and gattc_cbs to const with casts at API calls |
| tools/bt_tools.c | Converts le_conn_options and multiple command tables (g_cmd_tables, g_set_cmd_tables, g_get_cmd_tables, g_pair_cmd_tables) to const with casts |
| tools/async/scan.c | Converts scan_options and g_scanner_async_tables to const with casts |
| tools/async/log.c | Converts g_log_async_tables to const with cast |
| tools/async/gatt_client.c | Converts g_gattc_async_tables and gattc_cbs to const with casts |
| tools/async/gap.c | Converts le_conn_options and multiple command tables to const with casts |
| tools/async/adv.c | Converts adv_options, adv_stop_options, g_adv_async_tables, and adv_callback to const with casts |
| tools/adv.c | Converts adv_options, adv_stop_options, g_adv_tables, and adv_callback to const with casts |
| tools/a2dp_source.c | Converts g_a2dp_tables to const with cast |
| service/stacks/zephyr/sal_spp_interface.c | Converts spp_attrs_template and g_rfcomm_ops to const with casts; adds forward declarations |
| service/stacks/zephyr/sal_hid_device_interface.c | Converts hid_attrs_template and hid_callback to const with casts |
| service/stacks/zephyr/sal_hfp_hf_interface.c | Converts hf_callbacks to const with cast |
| service/stacks/zephyr/sal_hfp_ag_interface.c | Converts g_hfp_ag_cb to const with cast |
| service/stacks/zephyr/sal_avrcp_interface.c | Converts avrcp_tg_cbks to const |
| service/stacks/zephyr/sal_adapter_le_interface.c | Converts g_conn_cbs, g_conn_auth_info_cbs, and g_setting_cbs to const with casts; adds forward declarations |
| service/stacks/zephyr/sal_adapter_interface.c | Converts g_conn_cbs, g_setting_cbs, g_conn_auth_info_cbs, and g_br_discovery_cb to const with casts |
| service/stacks/zephyr/sal_a2dp_interface.c | Converts sbc_src_ie, stream_ops, and a2dp_cbks to const with casts |
| service/profiles/spp/spp_service.c | Converts sppInterface to const |
| service/profiles/hid/hid_device_service.c | Converts deviceInterface to const |
| service/ipc/socket/src/bt_socket_spp.c | Converts g_spp_socket_cb to const with cast |
| service/ipc/socket/src/bt_socket_scan.c | Converts g_scanner_socket_cb to const with cast |
| service/ipc/socket/src/bt_socket_advertiser.c | Converts g_advertiser_socket_cb to const with cast |
| framework/btwrap/async/bt_gatt_feature.c | Converts s_feature_gattc_cbs to const with cast |
| feature/feature_async/src/bluetooth_ble_impl.c | Converts adv_callback and gattc_cbs to 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_tables, ARRAY_SIZE(g_hfp_tables), argc, argv); | ||
| ret = execute_command_in_table(handle, (bt_command_t *)g_hfp_tables, ARRAY_SIZE(g_hfp_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 qualifier is a code smell that indicates an API design issue. While the cast is functionally safe here (since execute_command_in_table only reads the table), it would be better to update the execute_command_in_table function signature to accept a const pointer: int execute_command_in_table(void* handle, const bt_command_t* table, ...). This would eliminate the need for casts throughout the codebase and improve type safety.
| } | ||
|
|
||
| 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 qualifier unnecessarily. The API functions that receive these callback structures should be updated to accept const pointers if they don't modify the callbacks. This pattern is repeated throughout the codebase and indicates that the underlying Bluetooth stack APIs (bt_gattc_create_connect, bt_le_start_advertising, etc.) should have const-correct signatures for callback parameters that are only stored and never modified.
| #define SET_LE_PHY_USAGE "set le tx and rx phy, params: <addr><txphy><rxphy>(0:1M, 1:2M, 2:CODED)" | ||
|
|
||
| static bt_command_t g_cmd_tables[] = { | ||
| static const bt_command_t g_cmd_tables[] = { |
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.
While this PR successfully converts several command tables to const in modified files, there appear to be similar command tables in other tool files (e.g., a2dp_sink.c, avrcp_control.c, hid_device.c, l2cap.c, lea_*.c, log.c, panu.c, scan.c, spp.c) that would benefit from the same optimization. Consider extending this optimization to those files as well for consistency and maximum RAM savings across the entire codebase.
Memory Optimization: Change the bluetooth bt_tool hfp hf module to const for reduce the ram size.
bug:v/84973
Rootcause: To reduce RAM resource consumption, the
g_hfp_tables,in the bt_tools hfp hf module must be marked with the
constmodifier.This ensures it is compiled and linked into Flash memory instead of RAM.
Signed-off-by: huangyulong3 huangyulong3@xiaomi.com