RT3290 Bluetooth (rtbth) driver with Kernel >= 3.13 + PATCH!

NOTE Most of users here tell me that this doesn’t work (bluetooth detected and on, but no pairing or connection). There is a bug report still ongoing to resolve this issue.

In my previous post, I did compiled and installed this source coded driver from Ubuntu PPA without any hassle with my previous Ubuntu 12.04 LTS (Kernel 3.8.x). But after an-hour-long upgrade process to Ubuntu 14.04 LTS (with newer Kernel 3.13), I need to recompile (make clean; make) this driver but unfortunately it failed and I got this message :

/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: In function ‘rtbt_hps_iface_init’:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:404:13: warning: assignment from incompatible pointer type [enabled by default]
  hdev->send = rtbt_hci_dev_send;
             ^
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:406:6: error: ‘struct hci_dev’ has no member named ‘ioctl’
  hdev->ioctl = rtbt_hci_dev_ioctl;
      ^
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: At top level:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:83:20: warning: ‘pkt_type_str’ defined but not used [-Wunused-variable]
 static const char *pkt_type_str[]=
                    ^
make[2]: *** [/usr/src/rtbth-3.9.3/rtbth_core_bluez.o] Error 1
make[1]: *** [_module_/usr/src/rtbth-3.9.3] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic'
make: *** [all] Error 2


If you can’t see what triggering this error, see that output from bottom to up until you found something says error which obviously inside this line :

/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:406:6: error: ‘struct hci_dev’ has no member named ‘ioctl’
  hdev->ioctl = rtbt_hci_dev_ioctl;

Seems like familiar C-based compilation error message? Yes it does. A struct called hci_dev apparently changed its structure in newest version of kernel. And yes, it does changed in main kernel tree from this commit because ioctl is no use anymore. So I decided to modify rtbth_core_bluez.c line 406 and just commented this line.

//      hdev->ioctl = rtbt_hci_dev_ioctl;

Compiled it again, and got another error.

/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:216:2: error: too few arguments to function ‘hci_recv_frame’
  status = hci_recv_frame(skb);

When I blamed net/bluetooth/hci_core.c to see the function declaration of hci_recv_frame from Linux kernel tree, this function is now uses two argument (instead of one), an hci_dev of hdev and a sk_buff of skb) starting from this commit, which also adjusting every single bluetooth driver inside kernel tree. This adjustment is very simple: put an hdev inside hci_recv_frame function as an argument. I did this inside rtbth_core_bluez.c line #216.

        //status = hci_recv_frame(skb);
        status = hci_recv_frame(hdev, skb);
  CC [M]  /usr/src/rtbth-3.9.3/rtbth_core_bluez.o
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: In function ‘rtbt_hps_iface_init’:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:404:13: warning: assignment from incompatible pointer type [enabled by default]
  hdev->send = rtbt_hci_dev_send;
             ^
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: At top level:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:83:20: warning: ‘pkt_type_str’ defined but not used [-Wunused-variable]
 static const char *pkt_type_str[]=
                    ^
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: In function ‘rtbt_hci_dev_send’:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:92:6: warning: ‘status’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  int status;
      ^
  CC [M]  /usr/src/rtbth-3.9.3/rtbth_core_us.o
  CC [M]  /usr/src/rtbth-3.9.3/rtbth_hlpr_hw.o
  CC [M]  /usr/src/rtbth-3.9.3/rtbth_hlpr_dbg.o
  CC [M]  /usr/src/rtbth-3.9.3/rtbth_hlpr_linux.o
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘RtlCopyMemory’:
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c:95:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  return (int)memcpy(Destination, Source, Length);//sean wang linux, fix the build warning, type casting
         ^
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘ral_task_notify_exit’:
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c:557:16: warning: unused variable ‘pOSThread’ [-Wunused-variable]
  RTBT_OS_TASK *pOSThread = (RTBT_OS_TASK *)pTask->pOSThread;
                ^
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘ral_task_customize’:
/usr/src/rtbth-3.9.3/rtbth_hlpr_linux.c:570:16: warning: unused variable ‘pOSTask’ [-Wunused-variable]
  RTBT_OS_TASK *pOSTask = (RTBT_OS_TASK *)pTask->pOSThread;
                ^
  LD [M]  /usr/src/rtbth-3.9.3/rtbth.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /usr/src/rtbth-3.9.3/rtbth.mod.o
  LD [M]  /usr/src/rtbth-3.9.3/rtbth.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic'

Compiled again, no error.

But When I looked at the error message again, I noticed that there are some “warning” message which could be very dangerous but ignored by compiler by default such as incompatible pointer type.

/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:404:13: warning: assignment from incompatible pointer type [enabled by default]
  hdev->send = rtbt_hci_dev_send;
             ^

I reviewed again what ->send property expected as the value from hci_dev struct inside includes/net/bluetooth/hci_core.h. Then from this commit, it is clear that send expecting a function pointer with hdev as one its argument.

So I changed rtbt_hci_dev_send so it will including hdev as its first argument and move and skb moved as second argument in line 86 and commented previous hdev declaration in line 88:

//int rtbt_hci_dev_send(struct sk_buff *skb)
int rtbt_hci_dev_send(struct hci_dev *hdev, struct sk_buff *skb)
{
        //struct hci_dev *hdev = (struct hci_dev *)skb->dev;

Compiled again, VOILA! No error and no warning other than uninitialized/unused variable. So the last thing to do is to make install and then modprobe rtbth (as root of course).

Bluetooth works detecting my nearby devices.

As a reward for scrolling this post through this part, here I give you THE PATCH.

31 Comments

  1. Mário Saleiro

    You, sir, are awesome! Thanks a lot for this patch! You have just saved me a few hours! For some reason I couldn’t apply the patch (I had never done any patching so maybe I just did it wrong) but I applied the step by step changes that you described and everything worked perfectly! Big, big thanks! Keep up wit your great work! :)

  2. Helvete

    When I try the following command:
    $ patch < rtbth_core_bluez.c.patch
    It gives me an error:

    patching file rtbth_core_bluez.c
    Hunk #1 FAILED at 83.
    Hunk #2 FAILED at 213.
    Hunk #3 FAILED at 403.
    patch: **** malformed patch at line 36:

    How can I solve this? I'm very n00b with this things.

    1. Mike

      Hey there. Is your patched file up to date? I tried using it, but it gives me a lot of errors, like, specially not being able to create folders and files… specially a file named “Modules”, which I don’t know what is supposed to contain, so I can’t create it manually (Icreated some folders manually so that the Makefile has the place to create other things). I’d really appreciate your help.

    2. Neil Woolford

      Thanks, your patched version has got the basic bluetooth services working on my HP 255 laptop, running 14.04 LTS with kernel 3.13.0-74-generic.
      It works fine with my presentation controller, though won’t pair with my phone, but that may be a problem with the phone.

  3. Laos

    It gets compiled and installed… but when I want to pair a new device it gives me a failure. Please help me, I don’t know if I applied wrong the patch or there is some issue with the driver.

    1. wirama

      Unfortunately, I can’t figured it out when it comes to how this driver works internaly. It even doesn’t work when my bluetooth device turned off and then turned back on.

      1. Laos

        To me also it doesn’t worked anymore after turning off/on the bluetooth… in Ubuntu 13.10, but I was able to transfer files or use the whole bluetooth. But that driver, for kernel 3.13 , compiled and installed allows you to pair to devices or transfer files?

        1. wirama

          Maybe there is still some “fatal warning” while you compiled it. Could you recompiled it again and copy paste every single compilation message (make process) here?

  4. Laos

    hoest@hoest:~/Escritorio/rtbth-3.9.3$ make
    make -C /lib/modules/3.13.0-24-generic/build M=/home/hoest/Escritorio/rtbth-3.9.3 modules
    make[1]: se ingresa al directorio «/usr/src/linux-headers-3.13.0-24-generic»
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_main.o
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_init.o
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_init.c: In function ‘Rtbth_Set_Radio_Led’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_init.c:1185:3: warning: typedef ‘flag_t’ locally defined but not used [-Wunused-local-typedefs]
    } flag_t;
    ^
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_pci.o
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_pci.c: In function ‘rtbt_pci_probe’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_pci.c:198:1: warning: label ‘err_hps_iface’ defined but not used [-Wunused-label]
    err_hps_iface:
    ^
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_bluez.o
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_bluez.c:83:20: warning: ‘pkt_type_str’ defined but not used [-Wunused-variable]
    static const char *pkt_type_str[]=
    ^
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_bluez.c: In function ‘rtbt_hci_dev_send’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_bluez.c:92:6: warning: ‘status’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    int status;
    ^
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_core_us.o
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_hw.o
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_dbg.o
    CC [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.o
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘RtlCopyMemory’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c:95:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    return (int)memcpy(Destination, Source, Length);//sean wang linux, fix the build warning, type casting
    ^
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘ral_task_notify_exit’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c:557:16: warning: unused variable ‘pOSThread’ [-Wunused-variable]
    RTBT_OS_TASK *pOSThread = (RTBT_OS_TASK *)pTask->pOSThread;
    ^
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c: In function ‘ral_task_customize’:
    /home/hoest/Escritorio/rtbth-3.9.3/rtbth_hlpr_linux.c:570:16: warning: unused variable ‘pOSTask’ [-Wunused-variable]
    RTBT_OS_TASK *pOSTask = (RTBT_OS_TASK *)pTask->pOSThread;
    ^
    LD [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth.o
    Building modules, stage 2.
    MODPOST 1 modules
    CC /home/hoest/Escritorio/rtbth-3.9.3/rtbth.mod.o
    LD [M] /home/hoest/Escritorio/rtbth-3.9.3/rtbth.ko
    make[1]: se sale del directorio «/usr/src/linux-headers-3.13.0-24-generic»

    That’s all. As I can see there are only 2 messages from the rtbth_core_bluez.c, I already applied the changes to that file, compiled and installed but the bluetooth is still giving me the error when pairing with X device.

  5. Mario Ray Mahardhika

    Thank you, om. Ane coba dulu, moga2 masih jalan di kernel 3.14.1 yang lagi ane pake. Betewe, 3.13 itu short term release, bentar lagi EOL. Kalo bisa test n update kalo perlu di kernel 3.14.X.

  6. Mario Ray Mahardhika

    Hmm… masih banyak issue juga :(
    - Kalo diturn off, gak bisa diturn on lagi
    - Nyoba pair (tanpa ngutak-ngatik config), lampu indikator mati terus gak bisa gonta-ganti config lagi (tapi module tetep jalan, gak bisa diremove bahkan, ajaib)

    1. wirama

      A bit tricky, If you want a faster solution, download the entire dkms package, then tell dkms to install this package again and uninstall it.

  7. Jean

    I’ve got the same problem as Kristian. Bluetooth is on and the devices are detected but we can’t pair them. I use the kernel 3.13.0-24.

  8. TanCT

    Hi Wirama
    Thank you very much for the patch.
    It is working like a charm on my HP 15-n238TX 3.17.0 Linux Porteus laptop. It can be paired with my Samsung Galaxy S4. Send and receive files without problem.
    The only problem is there is one way speech path when using for audio/headset operation.
    It would be nice if there is a patch for that as well.

  9. Lois Fikom

    how to fix this error message?

    lois@maya-1730:~/Downloads/rtbth-3.9.3$ sudo /etc/init/bluetooth.sh
    insmod: ERROR: could not insert module /etc/Wireless/RT3290/rtbth.ko: Invalid module format
    mknod: ‘/dev/rtbth’: File exists
    /etc/init/bluetooth.sh: line 4: /etc/Wireless/RT3290/rtbt: cannot execute binary file: Exec format error

  10. Adam

    Hi!

    Cool, now works the BT detection, it’s a good thing. If you can spend some time check that the BT is useless, we can’t use at all, can’t pair, can’t send and recieve any files. Maybe I can help but I’m not an atom geek code digger :D just a web developer and a power engineer and programming addict. Maybe there is a fix but so deep in the code we should dig it up.

    Adam

  11. the_NetZ

    Any help with kernel 4.x (specifically 4.1.2), doesn’t work . I can scan and attempt to pair/connect with bluetoothctl but always get org.bluez.Error.Failed or org.bluez.Error.ConnectionAttemptFailed

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *