linux - 无法创建 RFCOMM TTY : Address already in use

标签 linux bluetooth tty bluez rfcomm

我在我的服务器中监听蓝牙连接:

rfcomm listen rfcomm1 1

然后我连接到我的蓝牙客户端并出现此消息:

Connection from XX:XX:XX:XX:XX:XX to /dev/rfcomm1
Press CTRL-C for hangup

这意味着一切正常...

然后我通过在服务器或客户端中执行 Ctrl+C 来完成我的连接。

在此之后,我再做一次:

rfcomm listen rfcomm1 1

但是这一次,当我连接客户端时,我收到了这条消息:

Can't create RFCOMM TTY: Address already in use

所以我去检查哪些连接是打开的:

rfcomm -a

我可以看到连接显示为已关闭,但一旦断开连接就不会出现...

rfcomm1: XX:XX:XX:XX:XX:XX -> XX:XX:XX:XX:XX:XX channel 1 closed [reuse-dlc release-on-hup ]

最奇怪的是,有时,断开连接成功,我可以毫无问题地重新连接。

EDIT

我发现当设备保持连接大约10秒或更长时间时,断开连接成功。但是当这个时间更短时(快速连接/断开连接),问题就出现了。

如果发生故障时,我会:

dmesg

这是打印出来的:

[11800.001527] Bluetooth: TIOCGSERIAL is not supported
[11800.033063] Bluetooth: TIOCGSERIAL is not supported
[11926.708438] Bluetooth: TIOCGSERIAL is not supported
[11934.918197] Bluetooth: TIOCGSERIAL is not supported
[11934.926194] Bluetooth: TIOCGSERIAL is not supported
[11934.926284] ------------[ cut here ]------------
[11934.926297] WARNING: CPU: 1 PID: 2316 at /build/linux-Pcn0xK/linux-4.4.0/drivers/tty/tty_port.c:143 tty_port_destructor+0x7a/0x80()
[11934.926300] Modules linked in: minidriver(OE) nls_utf8 isofs rfcomm bnep arc4 ath5k snd_hda_codec_realtek uvcvideo ath mac80211 snd_hda_codec_hdmi snd_hda_codec_generic snd_hda_intel videobuf2_vmalloc snd_hda_codec samsung_laptop videobuf2_memops snd_hda_core btusb videobuf2_v4l2 btrtl snd_hwdep videobuf2_core coretemp btbcm cfg80211 snd_pcm v4l2_common btintel snd_seq_midi joydev videodev bluetooth snd_seq_midi_event serio_raw media snd_rawmidi input_leds snd_seq snd_seq_device snd_timer snd soundcore shpchp lpc_ich mac_hid binfmt_misc parport_pc ppdev lp parport autofs4 hid_logitech ff_memless uas usb_storage hid_generic usbhid hid amdkfd amd_iommu_v2 radeon psmouse pata_acpi i2c_algo_bit ttm sky2 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops video fjes drm [last unloaded: minidriver]

[11934.926401] CPU: 1 PID: 2316 Comm: kworker/1:1 Tainted: G        W  OE   4.4.0-97-generic #120-Ubuntu
[11934.926404] Hardware name: SAMSUNG ELECTRONICS CO., LTD. R520/R522/R620               /R520/R522/R620               , BIOS 05LL.M025.20090916.Jay 09/16/20
[11934.926410] Workqueue: events release_one_tty
[11934.926413]  0000000000000286 c977cef9c84bca31 ffff88012ea3fd48 ffffffff813fabe3
[11934.926419]  0000000000000000 ffffffff81d386c0 ffff88012ea3fd80 ffffffff810812e2
[11934.926425]  ffff8800b5153800 ffff8800b67f6400 ffff8800b67f6400 ffffffffc06dc840
[11934.926430] Call Trace:
[11934.926438]  [<ffffffff813fabe3>] dump_stack+0x63/0x90
[11934.926445]  [<ffffffff810812e2>] warn_slowpath_common+0x82/0xc0
[11934.926450]  [<ffffffff8108142a>] warn_slowpath_null+0x1a/0x20
[11934.926455]  [<ffffffff8150357a>] tty_port_destructor+0x7a/0x80
[11934.926460]  [<ffffffff81503ce8>] tty_port_put+0x28/0x30
[11934.926471]  [<ffffffffc06d5fa8>] rfcomm_tty_cleanup+0x68/0x70 [rfcomm]
[11934.926475]  [<ffffffff814f91fb>] release_one_tty+0x3b/0xc0
[11934.926481]  [<ffffffff8109a635>] process_one_work+0x165/0x480
[11934.926486]  [<ffffffff8109a99b>] worker_thread+0x4b/0x4c0
[11934.926491]  [<ffffffff8109a950>] ? process_one_work+0x480/0x480
[11934.926496]  [<ffffffff810a0c75>] kthread+0xe5/0x100
[11934.926500]  [<ffffffff810a0b90>] ? kthread_create_on_node+0x1e0/0x1e0
[11934.926507]  [<ffffffff81843b8f>] ret_from_fork+0x3f/0x70
[11934.926511]  [<ffffffff810a0b90>] ? kthread_create_on_node+0x1e0/0x1e0
[11934.926515] ---[ end trace a33c33d1fdbe410d ]---
[11936.001325] Bluetooth: TIOCGSERIAL is not supported
[11936.033194] Bluetooth: TIOCGSERIAL is not supported

当一切正常时(10 秒或更长时间),仅显示这些消息:

[11936.001325] Bluetooth: TIOCGSERIAL is not supported
[11936.033194] Bluetooth: TIOCGSERIAL is not supported
[11936.001325] Bluetooth: TIOCGSERIAL is not supported
[11936.033194] Bluetooth: TIOCGSERIAL is not supported

最佳答案

你试过使用release吗?

sudo rfcomm release 0

或者直接将您的设备添加到 /etc/bluetooth/rfcomm 中,然后绑定(bind)它,然后在完成后尝试发布。

sudo rfcomm bind 0

关于linux - 无法创建 RFCOMM TTY : Address already in use,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46735997/

相关文章:

ios - 在 iOS 上通过蓝牙打印

Android 阻止蓝牙配对对话框

android - BluetoothDevice getName() 方法在 Android 12 中返回 null

linux - 如何编写 Linux 内核模块?

linux - 一个循环中的两个变量 - 第一个作为第二个变量

php无法无错误上传大文件

docker - 为什么在运行 yarn 脚本时我的终端输出与其等效的 bash 脚本不同?

c - 虚拟 tty 中的管道使用

c - 如何为输入 la shell 的 `bg` 命令创建后台进程 block ?

c - 如何将返回代码传递给 at_exit 函数