Skip to content
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

error: getting "short buffer" error when using Bluetooth #58

Open
deadprogram opened this issue Jan 7, 2025 · 4 comments
Open

error: getting "short buffer" error when using Bluetooth #58

deadprogram opened this issue Jan 7, 2025 · 4 comments

Comments

@deadprogram
Copy link
Contributor

After looking thru logs related to tinygo-org/bluetooth#301 I found something that might be related.

It is after the log message short buffer: length= 12 hcilen 16 rlen 16 buflen 12 that things fail.

Log excerpt here:

time=1970-01-01T00:00:01.194Z level=INFO msg=Init:done took=1.191638s                   
Enabling CYW43439 device                                                                                                       
hci send command 3075                                                                                                          
time=1970-01-01T00:00:01.195Z level=DEBUG msg=bp_write addr=427548 len=8    
time=1970-01-01T00:00:01.201Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
time=1970-01-01T00:00:01.201Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401030c00                                                                                          
evtCmdComplete 3075 0                                                                                                          
hci send command 3073 ffffffffffffff3f                                                                                         
time=1970-01-01T00:00:01.359Z level=DEBUG msg=bp_write addr=427556 len=16   
time=1970-01-01T00:00:01.361Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
time=1970-01-01T00:00:01.362Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401010c00                                                                                          
evtCmdComplete 3073 0                                                                                                          
hci send command 8193 ff03000000000000                                                                                         
time=1970-01-01T00:00:01.369Z level=DEBUG msg=bp_write addr=427572 len=16   
time=1970-01-01T00:00:01.371Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
time=1970-01-01T00:00:01.371Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401012000                                                                                          
evtCmdComplete 8193 0                                                                                                          
Enabled CYW43439 device                                                                                                        
added characteristic 2 3 00002a00-0000-1000-8000-00805f9b34fb                                                                  
added characteristic 4 5 00002a01-0000-1000-8000-00805f9b34fb                                                                  
added service 1 5 00001800-0000-1000-8000-00805f9b34fb                                                                         
added characteristic 7 8 00002a05-0000-1000-8000-00805f9b34fb                                                                  
added service 6 9 00001801-0000-1000-8000-00805f9b34fb                                                                         
hci send command 8198 000800080000000000000000000700                                                                           
time=1970-01-01T00:00:01.381Z level=DEBUG msg=bp_write addr=427588 len=24   
time=1970-01-01T00:00:01.383Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
time=1970-01-01T00:00:01.384Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401062000                                                                                          
evtCmdComplete 8198 0                                                                                                          
hci send command 8200 0302010600000000000000000000000000000000000000000000000000000000
time=1970-01-01T00:00:01.391Z level=DEBUG msg=bp_write addr=427612 len=40   
time=1970-01-01T00:00:01.393Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
time=1970-01-01T00:00:01.394Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401082000                                                                                          
evtCmdComplete 8200 0                                                                                                          
hci send command 8201 0e0d08476f20426c7565746f6f74680000000000000000000000000000000000
time=1970-01-01T00:00:01.401Z level=DEBUG msg=bp_write addr=427652 len=40   
time=1970-01-01T00:00:01.403Z level=DEBUG msg=hci_buffered buffered=10 avail=4084                    
time=1970-01-01T00:00:01.404Z level=DEBUG msg=hci_buffered buffered=10 avail=4084
hci event data recv: 6 040e0401092000                                                                                          
evtCmdComplete 8201 0                                                                                                          
hci send without response command 8202 01                                                                                      
time=1970-01-01T00:00:01.411Z level=DEBUG msg=bp_write addr=427692 len=12        
advertising...                                                                                                                 
hci send command 4105                                                                                                          
time=1970-01-01T00:00:01.413Z level=DEBUG msg=bp_write addr=427704 len=8           
time=1970-01-01T00:00:01.415Z level=DEBUG msg=hci_buffered buffered=10 avail=4084              
time=1970-01-01T00:00:01.416Z level=DEBUG msg=hci_buffered buffered=10 avail=4068                                              
time=1970-01-01T00:00:01.417Z level=DEBUG msg=hci_buffered buffered=10 avail=4068                                              
time=1970-01-01T00:00:01.417Z level=DEBUG msg=hci_buffered buffered=10 avail=4068
short buffer: length= 12 hcilen 16 rlen 16 buflen 12                                                                           
Go Bluetooth / 00:00:00:00:00:00                                                                                               
time=1970-01-01T00:00:01.420Z level=DEBUG msg=hci_buffered buffered=16 avail=4080                                              
time=1970-01-01T00:00:01.421Z level=DEBUG msg=hci_buffered buffered=16 avail=4080         
unknown packet data recv: 2 18 0c00                                                                                            
hci poll unknown packet: bluetooth: HCI unknown error 0c00
@deadprogram
Copy link
Contributor Author

@soypat just looking at https://github.com/embassy-rs/embassy/tree/main/cyw43-firmware vs the files in https://github.com/soypat/cyw43439/tree/main/firmware

Shouldn't we be using the exact same files/names?

@soypat
Copy link
Owner

soypat commented Feb 20, 2025

If the files match bit by bit then they should have the same name so the reference is easier to track. Want to submit a CL?

@deadprogram
Copy link
Contributor Author

deadprogram commented Feb 20, 2025

Actually I found the issue:
https://github.com/soypat/cyw43439/blob/main/bluetooth.go#L258

The value being returned by this function should be length+1.

I tested this by modifying the value being returned here https://github.com/tinygo-org/bluetooth/blob/c74fb68742be8788734b1f65830aa75289e2408e/adapter_cyw43439.go#L106

diff --git a/adapter_cyw43439.go b/adapter_cyw43439.go
index 07c1291..ae50a56 100644
--- a/adapter_cyw43439.go
+++ b/adapter_cyw43439.go
@@ -103,7 +103,11 @@ func (h *hciSPI) Read(buf []byte) (int, error) {
                return 0, err
        }
 
-       return r.Read(buf)
+       n, err := r.Read(buf)
+       if err != nil {
+               return 0, err
+       }
+       return n + 1, nil
 }
 
 func (h *hciSPI) Write(buf []byte) (int, error) {

@deadprogram
Copy link
Contributor Author

Which fixes tinygo-org/bluetooth#327 and a couple of other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants