📜 ⬆️ ⬇️

Linux usb phone howto

The document describes the installation and configuration of the USB phone for Linux, based on Yealink P1K. As a result, full control of calls from the phone was achieved, without the participation of the mouse and keyboard.

Introduction

I always wanted to have a mobile VoIP phone. This is a phone that is always with you, just like a mobile phone, but at the same time it is a VoIP phone, i.e. connected to your own IP PBX server (options like Nokia E65 and similar ones are not offered, I don’t want to warm the ears of mobile Wi-Fi with a microwave, so only USB phones remain). Windows users live simply, everyone there X-Lite and others include drivers for all kinds of USB phones, and all kinds of USB phones come with a disc with different softphones. But for those who have Linux on the desktop, the easy ways are ordered But nevertheless, go!

USB phone selection

Googling on “linux usb phone” showed that practically the only phone that was successfully connected was Yealink P1K USB phone. At the same time, half of those who tried and could not connect it. Well, let's try.
')
Installation

I will not describe the long way done in the process of walking on a rake. I can only say thanks to Thomas Reitmire, the author of the package Yeaphone www.devbase.at/voip/yeaphone.php , for his responsiveness and help. So, to get a mobile VoIP phone, we need the following components: - USB phone P1K - kernel module p1k yealink.ko - softphone linphone. - package yeaphone.

Yealink P1K USB phone and yealink.ko kernel module

Starting with some version of Linux, see section Device drivers → Input device support → Miscellaneous devices → Yealink usb-p1k voip phone. However, this module is outdated! It is necessary to take the module from the site of Thomas. Apparently, this is his home machine, so a copy of the files, relevant at the time of this writing, is attached here (Revision: 142). As Thomas said:

You might own a P1KH (USB ID 6993:b700) which uses a slightly different
communication protocol compared to the P1K. The P1K is the only model
supported by the kernel module shipped with the regular Linux kernel.
However if yours is a P1KH (or a B2K, B3G, P4K) then you should try my
version of this module:

svn co --username guest --password readonly svn://devbase.homelinux.org:5070/voip/yealink-module


This was just my case, and the output of lsusb proved this:

explorer t2-trunk # lsusb
...
Bus 003 Device 019: ID 6993:b700 Freshtel


The module was assembled on my relatively fresh 2.6.31-gentoo without any problems. The assembly is simple:

max@explorer /tmp/yealink-module/trunk $ make
make -C /usr/src/linux SUBDIRS=`pwd` modules
make[1]: Entering directory `/usr/src/linux-2.6.31-gentoo-r6'
CC [M] /tmp/yealink-module/trunk/yealink.o
Building modules, stage 2.
MODPOST 1 modules
CC /tmp/yealink-module/trunk/yealink.mod.o
LD [M] /tmp/yealink-module/trunk/yealink.ko
make[1]: Leaving directory `/usr/src/linux-2.6.31-gentoo-r6'
max@explorer /tmp/yealink-module/trunk $


The resulting file must be sent to the right place:

cp yealink.ko /lib/modules/2.6.31-gentoo-r6/kernel/drivers/input/

Softphone linphone and yeaphone wrapper

Another “false road” is the linphone softphone version. The fact is that all the packages published on the sites are for versions of the 2.x branch, and all the latest distributions install the linphone version 3.x. For example, I have net-voip / linphone-3.1.1 installed. The version of the yeaphone build is related to the version, something like this:

home/adyna/Desktop/yeaphone-0.1.6/src/ylcontrol.c:578: undefined reference to `gstate_get_state'
/home/adyna/Desktop/yeaphone-0.1.6/src/ylcontrol.c:579: undefined reference to `gstate_get_state'
/home/adyna/Desktop/yeaphone-0.1.6/src/ylcontrol.c:580: undefined reference to `gstate_get_state'


The fact is that in the 3rd branch changed the API. Thomas made the patch, but for some reason did not update the tar.gz packages, and the normally compiled code is only in svn. If there is any problem with the assembly, I recommend reading the comments section on the Thomas website. For your convenience, also attached to the article and the package with yaphone.

Fighting usbhid

Even after I got everything together, trying to start yaphone led to the message:

No appropriate handset found, exiting...

And it looked like this:

usbcore: registered new interface driver yealink
yealink: Yealink phone driver: 20090418 (C) Thomas Reitmayr, Henk Vergonet
usb 3-1: USB disconnect, address 22
usb 3-1: new full speed USB device using uhci_hcd and address 23
usb 3-1: configuration #1 chosen from 1 choice
generic-usb 0003:6993:B700.0020: hiddev0,hidraw3: USB HID v1.10 Device [Yealink Network Technology Ltd. VOIP USB Phone ] on usb-0000:00:1a.1-1/input3


The thing is that the usbhid module "takes" the device for itself, and the yealink module does not see it. If we ship the usbhid module (attention, we are left without a mouse), and temporarily move usbhid.ko, say to tmp, reload the yealink module, and plug in the phone, the dmesg message will be like this:

yealink: Yealink phone driver: 20090418 (C) Thomas Reitmayr, Henk Vergonet
usb 3-1: new full speed USB device using uhci_hcd and address 19
usb 3-1: configuration #1 chosen from 1 choice
yealink: Detected Model USB-P1KH (Version 0x1005)
yealink: Serial Number ff0adb4abc96
input: Yealink USB-P1KH as /devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.3/input/input20


As you can see, the phone was determined, and showed its serial number. In order not to have to play manually with the module each time, you need to add a rule to udev, which will call the script, “unlink” the phone from usbhid and “attach” it to yealink. The script is given in the appendix, but the output of his work:

explorer /tmp # sh /tmp/rebind-yealink.sh
Found Yealink phone at /sys/devices/pci0000:00/0000:00:1a.1/usb3/3-1
found HID interface at 3-1:1.3
successfully detached driver 'usbhid'
successfully reattached driver 'yealink'
explorer /tmp #


The output of dmesg will confirm that everything went well.

udev and permissions

The final touch is the adaptation /etc/udev/rules.d/99-yealink.rules

explorer ~ # cat /etc/udev/rules.d/99-yealink.rules
KERNEL=="event*", ATTRS{name}=="Yealink*", GROUP="max", RUN+="/bin/sh -c '/bin/chgrp max /sys$env{DEVPATH}/device/device/*'"
ACTION=="add|change", SUBSYSTEMS=="usb", ATTRS{idVendor}=="6993", ATTRS{idProduct}=="b700", RUN+="/usr/local/sbin/rebind-yealink.sh"


Please note that instead of max you need to insert the group under which your account works. To see your groups, run the groups command. Script rebind-yealink.sh is in the application. If at startup the phone issues something like this:

opmascha@explorer ~ $ yeaphone
path_sysfs = /sys/bus/usb/drivers/yealink/5-1:1.3/
path_event = /dev/input/event11
/sys/bus/usb/drivers/yealink/5-1:1.3/model: Permission denied
Detected handset Yealink USB-P1K
/sys/bus/usb/drivers/yealink/5-1:1.3/line2: Permission denied
/sys/bus/usb/drivers/yealink/5-1:1.3/line1: Permission denied
/sys/bus/usb/drivers/yealink/5-1:1.3/line3: Permission denied
/sys/bus/usb/drivers/yealink/5-1:1.3/hide_icon: Permission denied


This means that it is necessary to deal with 99-yealink.rules - it either does not work out because of a syntax error, or an error is made in the account. cd / sys / bus / usb / and watch permissions.

Startup

Register the start of the phone in a startup (rc.local, local.start or as it is correct in your distribution):

su - max -c '/usr/local/bin/yeaphone -w' > /dev/null 2>&1 &

Here you also need to change the max to the name of your account.

Customization

After installing all the components, you can proceed to setup. You need to configure:

SIP account


linphonec> proxy add
Adding new proxy setup. Hit ^D to abort.
Enter proxy sip address: sip:sipnet.ru
Your identity for this proxy: sip:1234567890@sipnet.ru
Do you want to register on this proxy (yes/no): yes
Specify register expiration time in seconds (default is 600): 180
Expiration: 180 seconds
Specify route if needed:
No route specified.
--------------------------------------------
sip address: sip:sipnet.ru
route:
identity: sip:1234567890@sipnet.ru
register: yes
expires: 180
registered: no
--------------------------------------------
Accept the above proxy configuration (yes/no) ?: yes
Proxy added.
linphonec> Registration on sip:sipnet.ru successful.
linphonec> Registration on sip:sipnet.ru successful.
linphonec>


Audio configuration

Next, you need to configure your audio device. If you are going to GTK interface, you can do it in it, otherwise as follows:

linphonec> soundcard list
0: ALSA: default device
1: ALSA: HDA Intel
2: ALSA: VOIP USB Phone
linphonec> soundcard use 2
Using sound device ALSA: VOIP USB Phone
linphonec>


This command will set all audio channels (playback, capture & ring) to use the USB of the phone.

Setting Yeaphone

Well, in conclusion, I will give an example of settings. The ~ / .yeahonerc file contains the configuration, and the ~ / .yaphone / ringtone / folder contains ringtones.

max@explorer /tmp $ cat ~/.yeaphonerc
intl-access-code 810
natl-access-code 8
country-code 7
display-id " --123--"
ringtone_default default_p1k.bin
#ringtone_default default_p1kh.bin
#ringtone_default falling2_p1k.bin
#ringtone_default falling_p1k.bin
#ringtone_default rising_p1k.bin
#ringtone_default special_p1k.bin


Ringtones are nasty, it would be great if someone added their own more melodic ones, like “a grasshopper was sitting in the grass” ...
Also, you need to make sure that only one proxy server is configured, and it is also selected as default in the ~ / .linphonerc file. If you receive such a message

Warning: Could not parse given sip address. A sip url usually looks like sip:user@domain

This means that you need to edit the pens ~ / .linphonerc.

Conclusion

As a result, as soon as I connect the USB phone Skype mate P1K to my laptop, for a maximum of 10 seconds it connects to the server. As soon as I pull out the USB cable from the laptop, the softphone removes the registration. For the 3rd day of operation no problems were found.

Applications

Udev rules
Script for udev on webhid phone weaning
Yaphone 0.1.8
Core module

Source: https://habr.com/ru/post/96814/


All Articles