-
Notifications
You must be signed in to change notification settings - Fork 8.3k
bt: services: gap_default: Extract GAP service from gatt implementation #94235
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: main
Are you sure you want to change the base?
Conversation
| # Copyright (c) 2025 Koppel Electronic | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config BT_GAP_DEFAULT |
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.
This config name is too generic. The GAP Service is only one component of GAP. I suggest something like BT_GAP_SVC_DEFAULT_IMPL.
| help | ||
| Enable the default GATT Generic Access Service. | ||
| Enabled by default provides basic GAP functionality. | ||
| If disabled user can provide its own implementation in the code. |
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.
I think we should say "must provide" and maybe "otherwise the system is not Bluetooth qualification compliant" or similar.
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.
I started it from "must" but then I thought that not everybody cares about being qualification compliant. But the wording like:
If disabled, it is the application responsibility to provide its own implementation
of GAP service, otherwise the system is not Bluetooth qualification compliant.
Probably explains everything and not "forces" anybody to do anything - freedom :)
| strlen(name)); | ||
| } | ||
|
|
||
| #if defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE) |
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 configs for the GAP Service should be moved Kconfig.gap_default.
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.
Yes. I am just wondering if it Kconfig.gap_default is good place for it. Maybe we should have Kconfig.gap - with all its configurations and then Kconfig.gap_default.
| /* This checks if the range entered is valid */ | ||
| BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_MIN_INT > 3200 && | ||
| CONFIG_BT_PERIPHERAL_PREF_MIN_INT < 0xffff)); | ||
| BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_MAX_INT > 3200 && | ||
| CONFIG_BT_PERIPHERAL_PREF_MAX_INT < 0xffff)); | ||
| BUILD_ASSERT(!(CONFIG_BT_PERIPHERAL_PREF_TIMEOUT > 3200 && | ||
| CONFIG_BT_PERIPHERAL_PREF_TIMEOUT < 0xffff)); | ||
| BUILD_ASSERT((CONFIG_BT_PERIPHERAL_PREF_MIN_INT == 0xffff) || | ||
| (CONFIG_BT_PERIPHERAL_PREF_MIN_INT <= | ||
| CONFIG_BT_PERIPHERAL_PREF_MAX_INT)); | ||
| BUILD_ASSERT((CONFIG_BT_PERIPHERAL_PREF_TIMEOUT * 4U) > | ||
| ((1U + CONFIG_BT_PERIPHERAL_PREF_LATENCY) * | ||
| CONFIG_BT_PERIPHERAL_PREF_MAX_INT)); |
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.
I'm not sure whether this is not GAP Service specific or even GATT specific. They are used in conn.c. But on the other hand they are defined under "ATT and GATT options". There seems to be a mistake here one way or the other. @jhedberg, should we move these configs out of "ATT and GATT" into a generic GAP space?
It's clearly not right to have these assertions here while the configs are used in conn.c.
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.
Yes, seems like they should move to some GAP-specific place. Btw, some of those build asserts should probably be converted into range directives in Kconfig.
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.
@jhedberg @alwa-nordic - should I just leave this assertions in the gatt.c for the purpose of this PR?
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.
I will do it right now - it looks little odd as now we have only the parameter checking in the gatt.c. But I get it that it is better not to move it to the module that may be disabled.
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 extracts the Generic Access Service (GAP) implementation from the GATT core files into a separate, configurable service module. This allows users to disable the default GAP implementation and provide their own custom implementation when needed.
Key changes:
- Creates a new configurable GAP service module in the services directory
- Removes GAP implementation from the core GATT files
- Maintains 100% compatibility with existing functionality through default enablement
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| subsys/bluetooth/services/gap_default.c | New file containing the extracted GAP service implementation |
| subsys/bluetooth/services/Kconfig.gap_default | Configuration file for the default GAP service |
| subsys/bluetooth/services/Kconfig | Includes the new GAP configuration |
| subsys/bluetooth/services/CMakeLists.txt | Builds the GAP service conditionally |
| subsys/bluetooth/host/gatt.c | Removes the GAP service implementation |
| include/zephyr/bluetooth/gap.h | Adds service name definition for consistency |
Comments suppressed due to low confidence (1)
|
|
||
| #if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE) | ||
| #define GAP_APPEARANCE_PROPS (BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE) | ||
| #if defined(CONFIG_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN) |
Copilot
AI
Aug 8, 2025
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.
Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN to match the naming convention.
| #if defined(CONFIG_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN) | |
| #if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN) |
| BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, | ||
| BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, | ||
| BT_GATT_PERM_READ | | ||
| #if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN) |
Copilot
AI
Aug 8, 2025
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.
Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_AUTHEN to match the naming convention.
| #if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN) | |
| #if defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_AUTHEN) |
| BT_GATT_PERM_READ | | ||
| #if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN) | ||
| BT_GATT_PERM_WRITE_AUTHEN, | ||
| #elif defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_ENCRYPT) |
Copilot
AI
Aug 8, 2025
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.
Configuration macro name is inconsistent with the pattern used elsewhere. Should be CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_ENCRYPT to match the naming convention.
| #elif defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_ENCRYPT) | |
| #elif defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE_ENCRYPT) |
|
Can we please discuss now mainly if this is the way we wish to go? If yes - I will work on it little more before changing it into valid PR. Now it is rather proof of concept to discuss this vs #93946. I know we can implement both - but to be honest, any of this two just solves my issues. This one I think gives more freedom to the user, but requires (a little) more work from the application perspective if the user wants to overwrite default functionality. |
To me it sounds like a reasonable approach at least, i.e. have a default implementation which can be completely overridden by the app if it wants to. |
ace01bc to
38b4d8a
Compare
|
|
I generally like and approve of the idea that Zephyr provides a GAP service that works out of the box, similar to DIS, BAS, etc., and where users can choose to define and implement their own (similar to the other services). 2 things we need to consider for this approach is
Both of the above can be verified at runtime, where we in |
|
Discussed in the Bluetooth WG meeting. Consensus was to move the GAP service to |
38b4d8a to
3214e90
Compare
|
Just a rebase before any changes. |
9689adc to
5c141cb
Compare
|
@rkel please be consistent with the commit subject prefix. Take a look at e.g. |
47420b3 to
b34b4eb
Compare
|
@Thalley I had added some verification if there is exactly one GAP service in GATT database. |
cb3839c to
b511a1e
Compare
b511a1e to
0305318
Compare
|
|
@rkel Please press the "Ready for review" button once you think this is ready for reviews again :) I (and possibly others), will generally wait with reviewing PRs until they leave draft |
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
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| prompt "Security requirements" | ||
| default DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN | ||
| help | ||
| Select security requirements for writing device name by remote GATT |
Copilot
AI
Oct 3, 2025
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 help text incorrectly refers to 'device name' but this choice is for device appearance security requirements. Should be 'Select security requirements for writing device appearance by remote GATT clients.'
| Select security requirements for writing device name by remote GATT | |
| Select security requirements for writing device appearance by remote GATT |
| @@ -0,0 +1,55 @@ | |||
| /* gatt_gap_validate.c - GAP service inside GATT validation functions */ | |||
Copilot
AI
Oct 3, 2025
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 filename in the comment is incorrect. Should be 'gatt_gap_svc_validate.c' to match the actual filename.
| /* gatt_gap_validate.c - GAP service inside GATT validation functions */ | |
| /* gatt_gap_svc_validate.c - GAP service inside GATT validation functions */ |
2aa9db0 to
232bca6
Compare
Remove Generic Access Service implementation from gatt files and move it into separate file in services directory. The proposed name is just gap_default as it is default implementation that may be switched off by the user in purpose of providing the GAP implementation directly in the application. Signed-off-by: Radosław Koppel <[email protected]>
…NULL Set the unused argument of the name characteristic to NULL. This removes the reference from GAP service to the hci_core. Signed-off-by: Radosław Koppel <[email protected]>
Implement the verification if there is exactly one GAP service in GATT database. The verification is performed as soon as the GATT database is available and forbids to enable the Bluetooth if the configuration is not compatible with the Bluetooth Specification. The verification may be disabled by the user for better performance or deliberate implementation that is not compliant with the specification. Signed-off-by: Radosław Koppel <[email protected]>
Disable the GATT GAP service validation for the test. Signed-off-by: Radosław Koppel <[email protected]>
232bca6 to
8042113
Compare
WIP Signed-off-by: Radosław Koppel <[email protected]>
|



Remove Generic Access Service implementation from gatt files and move it into separate file in services directory.
The proposed name is just gap_default as it is default implementation that may be switched off by the user in purpose of providing the GAP implementation directly in the application.
In the end it serves the same purpose that #93946 but gives the user total freedom of implementation when needed in the same time being 100% compatible with the current solution.
I was testing it manually and now I can enable and disable default GAP implementation.
The main reason of this PR is to discuss if we wish to go into this solution instead of #93946.
To be done:
[v] - GAP service validation during bt_enable.
[ ] - review all configurations that need to be moved to Kconfig.gap_default
[ ] - sample with GAP reimplementation on App side
[ ] - test of the sample (BabbleSim?)
[ ] - update documentation