【问题标题】:Linux to Android Bluetooth Tethering (PAN)Linux 到 Android 蓝牙网络共享 (PAN)
【发布时间】:2018-07-08 04:39:51
【问题描述】:

我有一个启用蓝牙的 [嵌入式] Linux 设备,并希望通过蓝牙将其内部网络(未连接到互联网)共享到 Android 设备(已试用 Android 6.x 和现在 7.1.2 - Lineage OS [根])。该设置已经在 Linux 或 Windows 客户端上运行良好。 我阅读了大量的帖子和文档,但我无法让它在 Android 设备上运行:

我的 Linux 设备:dnsmasq 作为 DHPC 服务器,启用蓝牙和“bt-pan”[1] 已启动并正在运行(桥接接​​口称为 bt-pan0)。通过 Dbus-Events,我会自动“信任”任何新连接的设备。设备类(如果重要的话)使用 hciconfig 配置为 0x020000。

在我的 Android 手机上,我与我的 Linux 设备(热点)配对(自动运行)并连接(使用“互联网访问”)。 在 dnsmasq 日志中,我看到连接的设备正确获取了 IP 地址。

在 linux-box 中,我可以在发布的 IP 地址上 ping 手机,我看到一个新的 bnep0 设备正在创建并添加到 bt-pan0 网桥中。

当我通过adb shell 连接到我的手机时,我还看到使用我的 dnsmasq 提供的正确 IP/网络掩码设置创建了一个 bt-pan 设备。 不幸的是,当启用 Wifi 或 Mobile-Data 时 - 我无法通过它的 IP 地址 ping linux-box。当 Wifi 和 Mobile-Data 被禁用时 - 设置工作正常。 这是我通过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

bt-pan0 设备的 dnsmasq 配置中,我设置了一个空的 default-gw(dhcp-option 3)和一个正确的 DNS 服务器(dhcp-option 6)。 我阅读了有关设置 dhcp-option 121(无类静态路由)的信息,但这也不起作用(DHCP 请求不查询 121)...

如果有人知道发生了什么或知道此设置导致问题的原因 - 我会很高兴最终弄清楚这一点。

[1]https://github.com/mk-fg/fgtk/blob/master/bt-pan

【问题讨论】:

  • 除了ip r 之外,看看ip a 的输出会很有趣。特别是,bt-pan 确实获得了从 192.168.10.0/24 分配的地址?从当前输出来看,不清楚为什么ip r get 192.168.10.5 会产生 dev rmnet_data0。需要 iptables 和其他路由表的标记规则(例如,ip route get table bt-pan)才能完全理解发生了什么。请注意,ip route get 接受 'mark' 选项和 'oif' 选项,请参阅 ip r help。所以我猜ip route get 192.168.10.5 oif bt-pan 会通过 dev bt-pan 给出一条路线。
  • 我为请求的命令制作了一个 pastebin 文档。不幸的是ip route get table bt-pan 不起作用,因此我附上了ip route show table all。希望这会有所帮助 - 谢谢! pastebin.com/Lw8ZkHH8
  • 我在同一个地方,superuser.com/a/1337904 是解决方案。

标签: android linux networking bluetooth dnsmasq


【解决方案1】:

我一直不明白为什么路由不起作用。

幸运的是,我可以设置我正在使用的库的 SocketFactory (Paho MQTT)。 因此 - 我使用 ConnectivityManager 来查找蓝牙设备及其“网络”对象(提供“getSocketFactory”)以在 MQTT 中设置 SocketFactory。然后连接工作。

ConnectivityManager cm =(ConnectivityManager)ctx.getSystemService(CONNECTIVITY_SERVICE);
Networks[] nets = cm.getAllNetworks();

... 找到蓝牙设备并使用“getSocketFactory”。 查找蓝牙设备

cm.getNetworkInfo(network);

很有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    相关资源
    最近更新 更多