Ste*_* W. 6 linux networking dnsmasq android bluetooth
我有一个启用蓝牙的[嵌入式] Linux 设备,并希望通过蓝牙将其内部网络(未连接到互联网)共享到 Android 设备(尝试过 Android 6.x 和现在的 7.1.2 - Lineage OS [rooted]) 。该设置已经可以很好地与 Linux 或 Windows 客户端配合使用。我阅读了大量的帖子和文档,但我就是无法让它在 Android 设备上运行:
我的 Linux 设备:dnsmasq 作为 DHPC 服务器,启用蓝牙并且“bt-pan”[1] 已启动并运行(桥接口称为bt-pan0)。通过 Dbus-Events,我自动“信任”任何新连接的设备。使用 hciconfig 将设备类(如果重要)配置为 0x020000。
在我的 Android 手机上,我与我的 Linux 设备(热点)配对(自动工作)并连接(使用“互联网访问”)。在 dnsmasq 日志中,我看到连接的设备正确获取了 IP 地址。
从 linux-box,我可以 ping 已发布的 IP 地址上的移动电话,并且我看到一个新bnep0设备正在创建并添加到bt-pan0网桥中。
当我通过连接adb shell到手机时,我还看到bt-pan使用 dnsmasq 提供的正确 IP/网络掩码设置创建了一个设备。不幸的是,当启用 Wifi 或移动数据时 - 我无法通过 linux-box 的 IP 地址 ping 通它。当 Wifi 和移动数据被禁用时 - 设置工作正常。这是我执行的一些命令的输出adb shell- 如果需要更多输出,我会尽快提供(移动数据 IP 地址是我在粘贴时修改的):
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 * 255.255.255.0 U 0 0 0 bt-pan
123.456.78.16 * 255.255.255.252 U 0 0 0 rmnet_data0
# ip route get 192.168.10.5
192.168.10.5 via 123.456.78.18 dev rmnet_data0 src 123.456.78.17 uid 0
cache
# ip rule show
0: from all lookup local
10000: from all fwmark 0xc0000/0xd0000 lookup legacy_system
10500: from all oif dummy0 uidrange 0-0 lookup dummy0
10500: from all oif rmnet_data0 uidrange 0-0 lookup rmnet_data0
10500: from all oif bt-pan uidrange 0-0 lookup bt-pan
13000: from all fwmark 0x10063/0x1ffff lookup local_network
13000: from all fwmark 0x100b9/0x1ffff lookup rmnet_data0
13000: from all fwmark 0x100ba/0x1ffff lookup bt-pan
14000: from all oif dummy0 lookup dummy0
14000: from all oif rmnet_data0 lookup rmnet_data0
14000: from all oif bt-pan lookup bt-pan
15000: from all fwmark 0x0/0x10000 lookup legacy_system
16000: from all fwmark 0x0/0x10000 lookup legacy_network
17000: from all fwmark 0x0/0x10000 lookup local_network
19000: from all fwmark 0xb9/0x1ffff lookup rmnet_data0
19000: from all fwmark 0xba/0x1ffff lookup bt-pan
22000: from all fwmark 0x0/0xffff lookup rmnet_data0
23000: from all fwmark 0x0/0xffff uidrange 0-0 lookup main
32000: from all unreachable
Run Code Online (Sandbox Code Playgroud)
在设备的 dnsmasq 配置中,bt-pan0我设置了一个空的 default-gw(dhcp-option 3)和一个正确的 DNS 服务器(dhcp-option 6)。我读到了有关设置 dhcp-option 121 (无类静态路由)的信息,但这也不起作用(DHCP 请求不查询 121)...
如果有人知道发生了什么或知道为什么此设置会导致问题 - 我会很高兴最终弄清楚这一点。
我一直不明白为什么路由不起作用。
幸运的是,我可以设置我正在使用的库的 SocketFactory (Paho MQTT)。因此 - 我使用 ConnectivityManager 查找蓝牙设备及其“网络”对象(提供“getSocketFactory”)以在 MQTT 中设置 SocketFactory。然后连接就可以工作了。
ConnectivityManager cm =(ConnectivityManager)ctx.getSystemService(CONNECTIVITY_SERVICE);
Networks[] nets = cm.getAllNetworks();
Run Code Online (Sandbox Code Playgroud)
...找到蓝牙设备并使用“getSocketFactory”。查找蓝牙设备
cm.getNetworkInfo(network);
Run Code Online (Sandbox Code Playgroud)
有帮助
| 归档时间: |
|
| 查看次数: |
4622 次 |
| 最近记录: |