-
Notifications
You must be signed in to change notification settings - Fork 33
Bugfix/fix bluetooth bt tool scan moudle cb change to const #448
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 scan moudle cb change to const #448
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>
…o const for reduce the ram size. bug:v/84974 Rootcause: To reduce RAM resource consumption, the `g_hidd_tables`, in the bt_tools hid device 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/84975 Rootcause: To reduce RAM resource consumption, the `g_log_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/84976 Rootcause: To reduce RAM resource consumption, the `scan_options`, 'g_scanner_tables', 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>
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 implements memory optimization by marking static data structures as const to move them from RAM to Flash memory. The changes affect bluetooth bt_tools scan and log modules, along with various service layer interface files.
Changes:
- Mark static command tables, callback structures, and attribute databases as
constacross multiple bluetooth tool and service files - Add explicit casts to remove
constqualifiers when passing these structures to APIs that don't accept const pointers - Add forward declarations for unused functions in sal_adapter_le_interface.c
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/scan.c | Mark scan_options and g_scanner_tables as const, add cast when passing to execute_command_in_table_offset |
| tools/log.c | Mark g_log_tables as const, add cast when passing to execute_command_in_table |
| tools/hid_device.c | Mark g_hidd_tables as const, add cast when passing to execute_command_in_table |
| tools/hfp_hf.c | Mark g_hfp_tables as const, add cast when passing to execute_command_in_table |
| tools/hfp_ag.c | Mark g_hfp_ag_tables as const, add cast when passing to execute_command_in_table |
| tools/gatt_server.c | Mark attribute databases (s_dis_attr_db, s_bas_attr_db, s_iot_attr_db) and g_gatts_tables as const, add casts in service database structures |
| tools/gatt_client.c | Mark g_gattc_tables and gattc_cbs as const, add casts when passing to APIs |
| tools/bt_tools.c | Mark le_conn_options and multiple command tables as const, add casts when passing to execute_command_in_table |
| tools/async/scan.c | Mark scan_options and g_scanner_async_tables as const, add cast for command table |
| tools/async/log.c | Mark g_log_async_tables as const, add cast for command table |
| tools/async/gatt_client.c | Mark g_gattc_async_tables and gattc_cbs as const, add casts for both |
| tools/async/gap.c | Mark le_conn_options and various command tables as const, add casts for command tables |
| tools/async/adv.c | Mark adv_options, adv_stop_options, g_adv_async_tables, and adv_callback as const, add casts when passing to APIs |
| tools/adv.c | Mark adv_options, adv_stop_options, g_adv_tables, and adv_callback as const, add casts when passing to APIs |
| tools/a2dp_source.c | Mark g_a2dp_tables as const, add cast when passing to execute_command_in_table |
| service/stacks/zephyr/sal_spp_interface.c | Mark spp_attrs_template and g_rfcomm_ops as const, add casts when assigning ops pointer |
| service/stacks/zephyr/sal_hid_device_interface.c | Mark hid_attrs_template and hid_callback as const, add cast when registering callback |
| service/stacks/zephyr/sal_hfp_hf_interface.c | Mark hf_callbacks as const, add cast when registering callback |
| service/stacks/zephyr/sal_hfp_ag_interface.c | Mark g_hfp_ag_cb as const, add cast when registering callback |
| service/stacks/zephyr/sal_avrcp_interface.c | Mark avrcp_tg_cbks as const |
| service/stacks/zephyr/sal_adapter_le_interface.c | Mark connection callbacks as const, add unused forward declarations, add casts for callback registrations |
| service/stacks/zephyr/sal_adapter_interface.c | Mark connection callbacks as const, add casts for callback registrations |
| service/stacks/zephyr/sal_a2dp_interface.c | Mark codec IE, stream ops, and a2dp callbacks as const, add casts when registering |
| service/profiles/spp/spp_service.c | Mark sppInterface as const |
| service/profiles/hid/hid_device_service.c | Mark deviceInterface as const |
| service/ipc/socket/src/bt_socket_spp.c | Mark g_spp_socket_cb as const, add cast when passing to register_app |
| service/ipc/socket/src/bt_socket_scan.c | Mark g_scanner_socket_cb as const, add cast when passing to scanner_start_scan |
| service/ipc/socket/src/bt_socket_advertiser.c | Mark g_advertiser_socket_cb as const, add cast when passing to bt_le_start_advertising |
| framework/btwrap/async/bt_gatt_feature.c | Mark s_feature_gattc_cbs as const, add cast when passing to bt_gattc_create_connect_async |
| feature/feature_async/src/bluetooth_ble_impl.c | Mark adv_callback and gattc_cbs as const, add casts when passing to APIs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static bt_scanner_t* g_scanner = NULL; | ||
|
|
||
| static struct option scan_options[] = { | ||
| static const struct option scan_options[] = { |
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.
The PR title contains a spelling error: "moudle" should be "module".
|
|
||
| if (argc > 0) | ||
| ret = execute_command_in_table_offset(handle, g_scanner_tables, | ||
| ret = execute_command_in_table_offset(handle, (bt_command_t *)g_scanner_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.
Casting away const qualifier is unsafe and defeats the purpose of marking the data as const. The underlying issue is that execute_command_in_table_offset expects a non-const bt_command_t* parameter, but the function only reads from the table and doesn't modify it. The proper fix would be to update the function signature in tools/bt_tools.h to accept 'const bt_command_t*' instead, eliminating the need for this cast. This pattern appears throughout the codebase in this PR.
| } | ||
|
|
||
| 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 is unsafe. Similar to the bt_command_t tables issue, the proper fix would be to update API function signatures to accept const callback pointers where the callbacks are not modified. This pattern of casting away const appears throughout this PR for various callback structures (gattc_callbacks_t, advertiser_callback_t, etc.), suggesting a broader API design issue.
| @@ -250,11 +250,11 @@ static gatt_attr_db_t s_iot_attr_db[] = { | |||
| }; | |||
|
|
|||
| static gatt_srv_db_t s_iot_service_db = { | |||
| .attr_db = s_iot_attr_db, | |||
| .attr_db = (gatt_attr_db_t *)s_iot_attr_db, | |||
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 unsafe and indicates an API design issue. The gatt_srv_db_t structure should accept a const gatt_attr_db_t* pointer for attr_db since the attribute database is read-only data. This would eliminate the need for these casts throughout the code.
| static le_conn_info_t* le_conn_add(const bt_address_t* addr); | ||
| static le_conn_info_t* le_conn_find(const bt_address_t* addr); | ||
|
|
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.
These forward declarations appear to be unused. The functions le_conn_add and le_conn_find are declared but never defined or called anywhere in this file. These declarations should be removed unless they are intended for future use or are defined in a different translation unit.
| static le_conn_info_t* le_conn_add(const bt_address_t* addr); | |
| static le_conn_info_t* le_conn_find(const bt_address_t* addr); |
Memory Optimization: Change the bluetooth bt_tool scan module to const for reduce the ram size.
bug:v/84976
Rootcause: To reduce RAM resource consumption, the
scan_options,'g_scanner_tables', in the bt_tools scan module must be marked with the
constmodifier.This ensures it is compiled and linked into Flash memory instead of RAM.