-
Notifications
You must be signed in to change notification settings - Fork 33
Bugfix/fix bluetooth bt tool gatt client moudle cb change to const #442
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 gatt client moudle cb change to const #442
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>
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 a memory optimization by marking static callback structures and command tables as const to move them from RAM to Flash memory. The change targets the Bluetooth bt_tool GATT client module and related service layers to reduce RAM consumption.
Changes:
- Static callback structures (
gattc_cbs,adv_callback, various_cbstructures) marked asconst - Static command tables (
g_gattc_tables,g_cmd_tables, etc.) marked asconst - Cast to non-const pointers added when passing const structures to functions expecting non-const parameters
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/gatt_client.c | Mark GATT client command tables and callbacks as const |
| tools/bt_tools.c | Mark BT tools command tables and connection options as const |
| tools/async/scan.c | Mark scanner command tables and scan options as const |
| tools/async/log.c | Mark log command tables as const |
| tools/async/gatt_client.c | Mark async GATT client command tables and callbacks as const |
| tools/async/gap.c | Mark GAP command tables and connection options as const |
| tools/async/adv.c | Mark advertising command tables, options, and callbacks as const |
| tools/adv.c | Mark advertising command tables, options, and callbacks as const |
| tools/a2dp_source.c | Mark A2DP source command tables as const |
| service/stacks/zephyr/sal_spp_interface.c | Mark SPP SDP attributes and RFCOMM ops as const |
| service/stacks/zephyr/sal_hid_device_interface.c | Mark HID device SDP attributes and callbacks as const |
| service/stacks/zephyr/sal_hfp_hf_interface.c | Mark HFP HF callbacks as const |
| service/stacks/zephyr/sal_hfp_ag_interface.c | Mark HFP AG callbacks as const |
| service/stacks/zephyr/sal_avrcp_interface.c | Mark AVRCP TG callbacks as const |
| service/stacks/zephyr/sal_adapter_le_interface.c | Mark LE adapter callbacks and settings callbacks as const; add forward declarations |
| service/stacks/zephyr/sal_adapter_interface.c | Mark BR/EDR adapter callbacks and discovery callbacks as const |
| service/stacks/zephyr/sal_a2dp_interface.c | Mark A2DP codec info, stream ops, and callbacks as const |
| service/profiles/spp/spp_service.c | Mark SPP interface structure as const |
| service/profiles/hid/hid_device_service.c | Mark HID device interface structure as const |
| service/ipc/socket/src/bt_socket_spp.c | Mark SPP socket callbacks as const |
| service/ipc/socket/src/bt_socket_scan.c | Mark scanner socket callbacks as const |
| service/ipc/socket/src/bt_socket_advertiser.c | Mark advertiser socket callbacks as const |
| framework/btwrap/async/bt_gatt_feature.c | Mark GATT feature callbacks as const |
| feature/feature_async/src/bluetooth_ble_impl.c | Mark BLE feature advertising and GATT client callbacks as const |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| 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 qualifiers is technically undefined behavior in C and is a code smell. The proper fix would be to update the API signature of bt_gattc_create_connect to accept const gattc_callbacks_t* instead of gattc_callbacks_t*, as the callbacks are never modified (only stored and used for callbacks). This change would eliminate the need for the cast and improve type safety. Note that some parts of the codebase (e.g., service/ipc/binder/include/gattc_callbacks_stub.h) already use const callback pointers, suggesting the API should be updated for consistency.
|
|
||
| if (argc > 0) | ||
| ret = execute_command_in_table(handle, g_gattc_tables, ARRAY_SIZE(g_gattc_tables), argc, argv); | ||
| ret = execute_command_in_table(handle, (bt_command_t *)g_gattc_tables, ARRAY_SIZE(g_gattc_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 qualifiers is technically undefined behavior in C. The proper fix would be to update the API signature of execute_command_in_table to accept const bt_command_t* instead of bt_command_t*, as the command table is never modified (only read). This would eliminate the need for the cast and improve type safety.
| } | ||
|
|
||
| int ret = execute_command_in_table(handle, g_set_cmd_tables, ARRAY_SIZE(g_set_cmd_tables), argc, argv); | ||
| int ret = execute_command_in_table(handle, (bt_command_t *)g_set_cmd_tables, ARRAY_SIZE(g_set_cmd_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 qualifiers is technically undefined behavior in C. The proper fix would be to update the API signature of execute_command_in_table to accept const bt_command_t* instead of bt_command_t*, as the command table is never modified (only read). This pattern appears multiple times in the file (lines 557, 571, 874) and should be addressed systematically by updating the function signature.
| } | ||
|
|
||
| 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 qualifiers is technically undefined behavior in C. The proper fix would be to update the function signature to accept const struct bt_rfcomm_dlc_ops*, as the operations structure is never modified. This approach would eliminate the need for the cast and improve type safety.
| 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 reference functions and a type (le_conn_info_t) that don't exist anywhere in the codebase. These lines should be removed as they serve no purpose and will cause compilation warnings or errors if strict checking is enabled.
| 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 gatt client module 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
constmodifier.This ensures it is compiled and linked into Flash memory instead of RAM.