- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.2k
Bluetooth: host: Add support for retrieving the remote version #17246
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
Conversation
| All checks are passing now. checkpatch (informational only, not a failure)Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. | 
bd0aea3    to
    79788e8      
    Compare
  
    f9b7beb    to
    73451b9      
    Compare
  
    | Added the changes mentioned by @joerchan | 
| If I recall correctly, I suggested having a dedicated API to trigger the remote info, i.e bt_conn_remote_info so we don't cause extra traffic with the likes of bt_conn_info. | 
3251ca3    to
    cec8a54      
    Compare
  
    | With the latest commit, I have separated the retrieval of remote version into a new function bt_conn_remote_info like @Vudentz suggested and there no longer is a rv struct in bt_conn_info. | 
467dba9    to
    24d4df9      
    Compare
  
            
          
                subsys/bluetooth/host/hci_core.c
              
                Outdated
          
        
      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.
Remove and set
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.
Looking much better. I think this solution is the right one, instead of bundling this into con info. Also the callback is much better and optimal than the blocking call.
A couple of loose ends.
        
          
                subsys/bluetooth/host/hci_core.c
              
                Outdated
          
        
      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.
Should this be enclosed in #ifdef CONFIG_BT_REMOTE_VERSION ?
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.
It should be static atleast.
I think using IS_ENABLED(CONFIG_BT_REMOTE) { hci_read_remote_version() } is enough to optimize it out. So it should not be included this way.
Checking with nm there is no hci_read_remote_version in the zephyr.elf file.
        
          
                subsys/bluetooth/host/hci_core.c
              
                Outdated
          
        
      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.
Are you using BT_CONN_AUTO_VERSION_INFO before defining it or am I seeing the wrong commit order?
I see now, disregard this comment.
        
          
                subsys/bluetooth/shell/bt.c
              
                Outdated
          
        
      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.
Add a comma to the end of this line, in case the struct gets extended in the future
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.
Good point. 👍
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.
Looks great now.
Also, this PR reduces in 105 bytes the ROM footprint of samples/bluetooth/peripheral in its default config.
        
          
                subsys/bluetooth/host/hci_core.c
              
                Outdated
          
        
      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 handler should either be in normal_events[] or in prio_events[] but not both. I guess you're "deprioritizing" it along with this PR, so the above chunk should be removed.
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.
Thanks. That is an oversight. Will remove.
        
          
                subsys/bluetooth/host/hci_core.h
              
                Outdated
          
        
      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.
Isn't the move of this define unnecessary now?
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 will move it back again.
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.
Revert prio changes not complete,
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.
Looks like doc changes are all in the doxygen comments, LGTM.
Avoid floating point usage when possible. E.g. on qemu_x86 this would
otherwise result in something like the following:
<err> os: Floating point unit not enabled
<err> os: eax: 0x00000024, ebx: 0x00000000, ecx: 0x00248fc8,
          edx: 0x00146120
<err> os: esi: 0x0012b30c, edi: 0x0024c628, ebp: 0x0024c638,
          esp: 0x0024c5b8
<err> os: eflags: 0x00000216 cs: 0x0008 cr3: 0x001465a0
<err> os: call trace:
<err> os: eip: 0x00121c8d
<err> os:      0x0010679c (0x127750)
<err> os:      0x0010693b (0x100f33)
<err> os:      0x001061bc (0x12b800)
<err> os:      0x001074fb (0x0)
<err> os:      0x00101151 (0x12b800)
<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception
<err> os: Current thread: 0x00146120 (shell_uart)
<err> os: Halting system
Signed-off-by: Johan Hedberg <[email protected]>
    bd847e8    to
    b316687      
    Compare
  
    | @jhedberg @carlescufi Fixed reverting of the prio changes. I had some trouble with git giving me the wrong commit in blame which ended up silently bringing the changes back. So please give this a thorough overview :) in case other cases of amending commits went wrong. I have looked over now and it looks ok to me. But I don't think it is right that I approve my own changes so I won't approve this. | 
        
          
                subsys/bluetooth/host/hci_core.c
              
                Outdated
          
        
      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.
It seems that you haven't introduced the  bt_hci_evt_read_remote_version_complete() yet in this patch - it only comes in a later one. Btw, a good way to check that each commit builds on its own is something like git rebase -i --exec="west build" origin/master. That will run the command given to the --exec switch for every commit that's part of the rebase.
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.
Actually, you haven't introduced the CONFIG_BT_REMOTE_VERSION option either here. I know this is a rather pedantic approach but it helps later when doing something like git bisect since every commit that it might land on should be sane and buildable.
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.
Thanks, good catch. I don't know exactly how it happened but some of my fixup commits ended up in the wrong commits.
The  --exec="" was a good tip. Although in this case it wouldn't have caught it as it still compiled due to the CONFIG_BT_REMOTE_VERSION not having been defined.
Moved the change to the right commit.
This commit reverts the change that moved the remote version event from a priority event to a normal event. This is done because the strategy for using this event has been changed and will be used with a callback instead of a semaphore that could be locked from the RX thread. This commit retains the infrastructure that was added in the controller so that moving events to priority processing is still possible. Signed-off-by: Joakim Andersson <[email protected]>
Refactor the handling of the host auto initiated LL procedures. This makes it easier to add new auto initiated procedures as well as reduced the maintenance by reducing code duplication. Signed-off-by: Joakim Andersson <[email protected]>
Make remote features and remote version accesible to the application through the bt_conn_get_remote_info object. The host will auto initiate the procedures. If the procedures have not finished with the application calls bt_conn_get_remote_info then EBUSY will be returned. The procedures should finish during the first 10 connection intervals. Signed-off-by: Sverre Storvold <[email protected]> Signed-off-by: Joakim Andersson <[email protected]>
Add printing of the remote version information whenever the new CONFIG_BT_REMOTE_VERSION option is enabled. Signed-off-by: Johan Hedberg <[email protected]>
| ((conn->role == BT_HCI_ROLE_MASTER) || | ||
| BT_FEAT_LE_SLAVE_FEATURE_XCHG(bt_dev.le.features))) { | ||
| err = hci_le_read_remote_features(conn); | ||
| if (!err) { | 
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.
Hi guys, @jhedberg @Blackladder
I wonder whether the condition is correct. Shouldn't it be just if (err) ? It looks like it was borrowed from the commits this PR was based on.
I found this issue when tried to update connection parameters from the app level. They are simply not updated, because of the timer-specifics involved in the call of slave_update_conn_param() which is below in this function. And this slave_update_conn_param() is not called when conditions like I mentioned return from the conn_auto_initiate()..
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.
if (!err) is the correct expression here. It returns on success of sending the command. If not success it moves to the next one. You can see it does that for all of the HCI procedures in this function. Once the procedure completes this function will be called and the next procedure should be initiated.
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.
Thanks for the reply!
Sorry, I still don't get it. Shouldn't the happy-flow mean that all calls should succeed (given that their corresponding if-conditions are true - IS_ENABLED):
- hci_le_read_remote_features()
- hci_read_remote_version()
- hci_le_set_phy()
- hci_le_set_data_len()
- slave_update_conn_param()
Why quit conn_auto_initiate() if PHY succeeds for example? Is there a relation between success on remote features and auto PHY negotiation, and DLE and Peripheral Conn Params Update Request?
My issue is that if slave_update_conn_param() is not called at all, then there is no way peripheral can initiate the update of connection parameters after the connection is established. Neither the initial auto update (slave_update_conn_param), nor from 'bt_le_conn_param_update()`. Isn't it a bug?
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.
@dnsglk The intention is to call all of them. But the three first in the list  are asynchronous, and only one can be active at a time.
If hci_le_read_remote_features is called, then conn_auto_initiate will be called again from bt_hci_evt_read_remote_version_complete, and this time it will call the next function in your list.
hci_le_set_data_len() and slave_update_conn_param() can be called simultaneously, so they don't have this behavior.
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 see now. In my case then, gdb shows that le_phy_update_complete() is not called for whatever reason...
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.
@joerchan thanks for spending time explaining it. Anyway, it still looks like something to improve IMO. Because, if remote doesn't respond to that query (which is my guess on why the phy callback is not triggered), it still means that not all of auto initialization has been completed.
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.
@dnsglk Can you create an bug-report with the missing le_phy_update_complete and tell us how to reproduce this problem? Please be as detailed as possible
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.
@joerchan I'll post a report if it I have more time to dig deeper into the issue. Thanks for understanding.
Make remote features and remote version accesible to the application
through the bt_conn_get_info object.
get_remote_version() is called if the remote version is not stored
in the new fields in struct bt_conn.