mynewt-mcumgr-cli icon indicating copy to clipboard operation
mynewt-mcumgr-cli copied to clipboard

Can't init hci

Open des-gan09 opened this issue 3 years ago • 6 comments

I was trying to run the mcumgr cli via the ble and encounter this error. I managed to circumvent this using sudo. Is there any other method without using sudo.

des-gan09 avatar Feb 22 '22 00:02 des-gan09

this tool uses so called "user channel" to access HCI interface and that requires CAP_NET_ADMIN privilege

sjanc avatar Feb 22 '22 09:02 sjanc

So how do i give myself CAP_NET_ADMIN privilege at the user level

des-gan09 avatar Feb 22 '22 10:02 des-gan09

When i tried the example 'mcumgr --conntype ble --connstring peer_name=Zephyr echo hello' i encountered an error that 'Error: [hci0]: can't init hci: can't down device: operation not permitted'. Using the command with sudo gave 'sudo: mcumgr: command not found' error. So how can i make it work?

muratdolaz avatar Oct 24 '22 11:10 muratdolaz

depends on where you put your mcumgr binary, you may try with sudo -E which preserves your local user environment variables (ie PATH), or you may provide full path to mcumgr binary

sjanc avatar Oct 25 '22 07:10 sjanc

I have just come across the same error two years later: "Error: [hci0]: can't init hci: can't down device: operation not permitted".

Giving the utility the CAP_NET_ADMIN capability worked for me; once you do so, the user does not need to be in sudoers when running the utility. To do so, I did the following under debian Bookworm. You'll need to run these commands as root, replacing the path with your installation location.

apt-get install libcap2-bin
setcap 'cap_net_admin=ep' /home/dev/go/bin/mcumgr

Could this capability be granted by the installer, or a warning given if a non-root user installs it? The error message alone does not make obvious what the solution should be, and I spent a lot of time trying to add my user to various groups for instance, under the assumption it was a permissions issue.

Thanks.

sk3p71c avatar Aug 02 '24 16:08 sk3p71c

Hi,

Yeah, I guess we could make error message more descriptive and also update web documentation...

sjanc avatar Aug 05 '24 08:08 sjanc