You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by "pfyra (via GitHub)" <gi...@apache.org> on 2023/08/11 07:36:54 UTC

[GitHub] [mynewt-nimble] pfyra opened a new issue, #1590: Host HCI commands not freed

pfyra opened a new issue, #1590:
URL: https://github.com/apache/mynewt-nimble/issues/1590

   Hello,
   
   I am using an STM32 (with FreeRTOS) connected through uart to an NXP 88w8987. While working on getting nimble to work I noticed that HCI commands sent from host to controller with ble_hs_hci_cmd_send are not freed. There is a buffer of size 1 (i.e. 1 command) so I got a crash on the second command due to failed memory allocation.
   
   I have modified nimble/host/src/ble_hs_hci_cmd.c like this:
   ble_hs_hci_cmd_send(uint16_t opcode, uint8_t len, const void *cmddata)
   {
       ....
       ble_transport_free_cmd(cmd);
       return rc;
   }
   
   and added the free-function to nimble/transport/src/transport.c:
   os_error_t ble_transport_free_cmd(void * cmd) {
     return os_memblock_put(&pool_cmd, cmd);
   }
   
   and now it works for me.  Is the free-ing missing or am I missing something?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [mynewt-nimble] pfyra commented on issue #1590: Host HCI commands not freed

Posted by "pfyra (via GitHub)" <gi...@apache.org>.
pfyra commented on issue #1590:
URL: https://github.com/apache/mynewt-nimble/issues/1590#issuecomment-1674486190

   Oh, silly me. 
   I used https://git.gitlab.arm.com/iot/open-iot-sdk/sdk/-/tree/main/components/bluetooth for integration at first (since uart_ll didn't exist a couple of weeks ago) and that integration layer did not call the ble_transport_free (I could probably have done it in the iotHciSendToController I provided, but that didn't occur to me). Now I have replaced that integration layer with the uart_ll and I apparently simply assumed the problem persisted since my (now extra) free'ing didn't cause any problems. 
   Thank you for the very fine piece of software and your very quick assistance!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [mynewt-nimble] andrzej-kaczmarek commented on issue #1590: Host HCI commands not freed

Posted by "andrzej-kaczmarek (via GitHub)" <gi...@apache.org>.
andrzej-kaczmarek commented on issue #1590:
URL: https://github.com/apache/mynewt-nimble/issues/1590#issuecomment-1674388846

   Hi Peter,
   
   On Fri, 11 Aug 2023 at 09:37, Peter ***@***.***> wrote:
   
   > Hello,
   >
   > I am using an STM32 (with FreeRTOS) connected through uart to an NXP
   > 88w8987. While working on getting nimble to work I noticed that HCI
   > commands sent from host to controller with ble_hs_hci_cmd_send are not
   > freed. There is a buffer of size 1 (i.e. 1 command) so I got a crash on the
   > second command due to failed memory allocation.
   >
   Commands are freed by transport, the host does not need to do this. I
   assume you use uart_ll transport since you have external controller so in
   this case it happens in hci_uart_tx_char @
   nimble/transport/uart_ll/src/hci_uart.c when last byte from command buffer
   was consumed. If it does not work for you, I'd suggest debugging that
   function to see what happens. I don't see anything wrong with that function
   at first glance.
   
   
   > I have modified nimble/host/src/ble_hs_hci_cmd.c like this:
   > ble_hs_hci_cmd_send(uint16_t opcode, uint8_t len, const void *cmddata)
   > {
   > ....
   > ble_transport_free_cmd(cmd);
   > return rc;
   > }
   >
   > and added the free-function to nimble/transport/src/transport.c:
   > os_error_t ble_transport_free_cmd(void * cmd) {
   > return os_memblock_put(&pool_cmd, cmd);
   > }
   >
   > and now it works for me. Is the free-ing missing or am I missing something?
   >
   
   This won't work properly with RAM transport since command buffers are
   passed directly to LL so there will be use-after-free error.
   
   BR,
   Andrzej
   
   
   
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/mynewt-nimble/issues/1590>, or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/ACJ6MDL24T6JOIPSTPMFZHLXUXOKFANCNFSM6AAAAAA3MRF7H4>
   > .
   > You are receiving this because you are subscribed to this thread.Message
   > ID: ***@***.***>
   >
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [mynewt-nimble] pfyra closed issue #1590: Host HCI commands not freed

Posted by "pfyra (via GitHub)" <gi...@apache.org>.
pfyra closed issue #1590: Host HCI commands not freed
URL: https://github.com/apache/mynewt-nimble/issues/1590


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org