简体   繁体   English

C++ linux 蓝牙 sdp_connect 仅在具有 root 权限的情况下才能成功

[英]C++ linux bluetooth sdp_connect only succeed with root privilege

I'm trying to run a bluetooth server program on Linux我正在尝试在 Linux 上运行蓝牙服务器程序
In order for my client device to find the server, I need to register my service profile on sdp为了让我的客户端设备找到服务器,我需要在 sdp 上注册我的服务配置文件
My code is basically similar to code on this page我的代码与此页面上的代码基本相似

The problem is that I need to get root privilege in order to make sdp_connect succeed问题是我需要获得 root 权限才能使sdp_connect成功
When running as a normal user, sdp_connect always returns NULL以普通用户sdp_connect运行时, sdp_connect总是返回NULL

Because the other part of my code requires a normal user (not root) environment, I'm wondering if I can make sdp_connect and the following sdp_record_register succeed without root access因为我代码的另一部分需要普通用户(不是root)环境,我想知道我是否可以在没有root访问权限的情况下使sdp_connect和以下sdp_record_register成功

Update更新

Just found a possible solution here刚刚在这里找到了一个可能的解决方案
I'm using Bluez5 and sdp_connect seems to be deprecated Bluez4 function, so I need to run the service in compatibility mode我正在使用 Bluez5 并且sdp_connect似乎已弃用 Bluez4 功能,因此我需要在兼容模式下运行该服务
Now it works, and it gives access of /var/run/sdp to all现在它可以工作了,并且它为所有人提供了/var/run/sdp访问权限
Just not sure if it is safe to give such permanent access只是不确定授予这种永久访问权限是否安全

As you rightly note, there have been 8 tools marked as deprecated as they are no longer maintained or have been replaced by other tools.正如您正确地注意到的那样,有 8 个工具被标记为已弃用,因为它们不再维护或已被其他工具取代。

Running with --compat would seem like a quick fix rather than a long term solution.使用--compat运行似乎是一个快速解决方案,而不是一个长期解决方案。

The supported APIs are Bluetooth Management API which is focused towards system level functions.支持的 API 是蓝牙管理API,它专注于系统级功能。

The application level is accessed through D-Bus and is spread over several documents in https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc应用层通过 D-Bus 访问,分布在https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc 中的几个文档

Adapter , Device , GATT , and profile are some of the common ones depending what you are trying to do. AdapterDeviceGATTprofile是一些常见的,具体取决于您要执行的操作。

Looking at the bluetoothctl source code can give some examples of how to use these APIs with C.查看bluetoothctl 源代码可以给出一些如何在 C 中使用这些 API 的示例。

There are more examples in the test directory but they are in Python: test 目录中有更多示例,但它们是在 Python 中的:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/testhttps://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM