USB串口转换器ttyUSB0权限问题

发布于 2024-11-10 12:06:15 字数 541 浏览 2 评论 0原文

我们正在开发一个从串行设备读取数据的应用程序。现有的 C++ 代码被重用为共享库(libProtocol.so 使用 NDK 构建)来读取和解码设备中的数据并将其传递给应用程序。但是当设备连接时,由于权限问题,共享库代码无法访问设备。在 adb shell 命令 ls -l/dev/ttyUSB0 中显示“crw-------- root root”。如果我手动从 adb 使用 chmod 777 ttyUSB0 ,然后运行该应用程序,它就能够打开该端口。 (如果我创建一个C++ exe来访问USB串行端口并在android环境中运行,它可以访问该端口,但从共享库访问失败)

  1. 是否可以永久更改权限?
  2. android 是否以 root 或其他用户身份运行?
  3. 一般来说 ttyUSB0 属于 dialout 组,为什么它显示为 root 和 crw-------- 而不是 crw-rw---- ?
  4. 为什么从 exe 访问可以,而从共享库访问却失败?

硬件平台:Beagle Board - XM 操作系统:Android Froyo 有人可以帮忙吗?

We are developing an application which reads data from a serial device. Existing C++ code is reused as a shared library (libProtocol.so is built using NDK) to read and decode the data from the device and pass it to the application. But when the device is connected, the shared library code is not able to access the device because of the permission issues. In adb shell command ls -l/dev/ttyUSB0 shows "crw------- root root". If I mannually use chmod 777 ttyUSB0 from adb and after that run the application, it is able to open the port. (If I create a C++ exe to access USB Serial port and run in android environment, it is able access the port but accessing from shared library fails)

  1. Is it possible to change the permissions permanently?
  2. Does android run as a root or any other user?
  3. Generally ttyUSB0 belongs to dialout group, why it is showing as root and crw------- instead of crw-rw---- ?
  4. Why accessing from exe works and accessing from shared library falils?

Hardware platform : Beagle Board - XM
OS: Android Froyo
Can anyone please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘寄 2024-11-17 12:06:15

您需要弄清楚设备文件的创建位置,并适当地设置权限。这可能位于 /init.rc 或类似文件中,或者可能位于 USB 设备插入时触发的内容中。对文件系统的部分设备名称(由特权用户)进行递归 grep 可以帮助您找到出现该字符串的所有内容,从而在几分钟内为您提供答案,至少前提是它是本机代码而不是dalvik 类文件(我认为不太可能)

Android 应用程序通常不会以 root 身份运行;让它们这样做是相当复杂的,因为它们通常不是按正常意义上启动的,而是从 zygote 进程中分叉出来的(因此可以共享公共库映射)。但一个选择是,Android 应用程序可以 - 非正式地 - 启动 setuid 二进制文件,并使用它们作为代理来执行操作,即,您可以拥有一些东西,将其 stdin 上收到的任何内容写入到端口,并打印从其端口上接收到的任何内容。标准输出。

You need to figure out where the device file is being created, and set the permissions appropriately. This may be in /init.rc or similar or it may be in something triggered upon USB device insertion. A recursive grep of the filesystem for part of the device name (by a priveleged user) may get you an answer in a couples of minutes by helping you find everything with an occurrence of that string, at least provided it's in native code and not a dalvik classfile (which I would consider unlikely)

Android applications do not normally run as root; it's quite complicated to make them do so, because they are not normally launched in the normal sense, but instead forked off of the zygote process (so common library mappings can be shared). But an option is that android apps can - unofficially - launch setuid binaries, and use them as proxies to do things, ie, you can have something that just writes anything received on its stdin to the port and prints anything received from the port on its stdout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文