This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

What is the best way from userspace to tell when ST kernel registration is complete with BT WILINK?



I’m using TI’s shared transport (ST) driver and am having trouble determining exactly when initialization is complete.

After inserting the btwilink module, is there some event that is available in user-space to tell me so? I changed the ordering of a few things on my development platform and now I need to be able to query the kernel (Linux 3.3) as soon as possible after wilink module insertion.

The ‘install’ file in ‘/sys/devices/platform/kim/install’ notifies me when the line discipline is ready to be installed by UIM, but that’s not quite what I’m looking for.

If I try to open a Bluetooth socket using hci_route/hci_open_dev in libbluetooth (which use the standard ioctl interface), I receive errors from the ioctl with the kernel. I know libbluetooth is not supported by these forums, but I believe my question has more to do with know when the ST and wilink modules have complete initialization within the kernel.

 Here is my dmesg output: 

# dmesg
(stc): st_tty_open
(stk) :line discipline installed
(stk) :TIInit_8.6.15.bts
(stk) :ldisc_install = 2
(stc):  st_reg_complete
(stc): protocol 9's cb sent 0
(stc): add_channel_to_table: id 4
(stc): st_register(2)
(stc): add_channel_to_table: id 2
(stc): st_register(3)
(stc): add_channel_to_table: id 3
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 4
hci0: type 1 len 5
hci0: type 1 len 6
hci0: type 1 len 11
hci0: type 1 len 12
hci0: type 1 len 4
hci0: type 1 len 5
hci0: type 1 len 5
hci0: type 1 len 4
hci0: type 1 len 5
hci0: type 1 len 6
hci0: type 1 len 6 
#

I don’t believe that the ‘hci0’ messages are part of ST, but part of the kernel Bluetooth modules initialization process (I may be wrong here though). 

I’m presuming that what I want is a notification in userspace of when the above dmesg output is complete. I would really like an event based solution, so I don't have to poll the output of some command.

  • Hi,

    Can you paste the logs for the below?
    "If I try to open a Bluetooth socket using hci_route/hci_open_dev in libbluetooth (which use the standard ioctl interface), I receive errors from the ioctl with the kernel."

    And also share the list of commands/API's that you execute?

    The BT Turn on mechanism w.r.t the user space is the same irrespective of whether you use ST or not. The "hdev->open" call is what the user space invokes to turn on BT. This is blocking until BT is turned on or till BT_REGISTER_TIMEOUT ( = 6 seconds).

    "I don’t believe that the ‘hci0’ messages are part of ST, but part of the kernel Bluetooth modules initialization process "
    You are correct - these are the stack init commands.

    Regards,
    Gigi Joseph.
  • Thanks for the response.

    Here are the requested logs and a test application/init script:

    test_app:

    #include <iostream>
    #include <stdlib.h>
    #include <errno.h>
    #include <fstream>
    
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/hci.h>
    #include <bluetooth/hci_lib.h>
    //#include <bluetooth/l2cap.h>
    //#include <bluetooth/sdp.h>
    //#include <bluetooth/sdp_lib.h>
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
       int route = -1;
       int devid = -1;
    
       ofstream kmsg("/dev/kmsg");
       if (kmsg.is_open())
       {
          // Initialize Bluetooth protocol stack and driver
          int status   = system("/path/to/bluetooth.sh start");
          if (WEXITSTATUS(status) == 0)
          {
             // Obtain route and socket
             route = hci_get_route(nullptr);
             if (route < 0)
             {
                kmsg << "DEBUG: failed hci_get_route - errno = " << errno << endl;
             }
    
             devid = hci_open_dev(route);
             if (devid < 0)
             {
                kmsg << "DEBUG: failed hci_open_dev - errno = " << errno << endl;
             }
    
             // Print values to kmsg log
             kmsg << "DEBUG: route = " << route << endl;
             kmsg << "DEBUG: devid = " << devid << endl;
          }
          else
          {
             kmsg << "DEBUG: script failure = " << status << endl;
          }
       }
       else
       {
          cerr << "Unable to open /dev/kmsg" << endl;
       }
    
       // Close socket
       if (devid >= 0)
       {
          hci_close_dev(devid);
       }
    	return 0;
    }
    

    bluetooth.sh:

    # cat /path/to/bluetooth.sh 
    
    uim="/usr/bin/uim"
    uim_args="-f /sys/devices/platform/kim"
    btdaemon="/usr/sbin/bluetoothd"
    case "$1" in
    	start)
    		start-stop-daemon -S -p /var/run/uim.pid -m -b -x $uim -- $uim_args
    		insmod /lib/modules/btwilink.ko
    		#do something with the device so the kernel doesn't time out:
    		hciconfig up > /dev/null
    		start-stop-daemon -S -v -p /var/run/bluetoothd.pid -m -x $btdaemon
    		;;
    	stop)
    		hciconfig hci0 down
    		start-stop-daemon -K -p /var/run/uim.pid
    		rmmod /lib/modules/btwilink.ko
    		;;
    	*)
    		echo "Usage: /path/to/bluetooth.sh {start|stop}"
    		exit 1
    esac
    
    echo "BT_MODULE_READY TO APP" > /dev/kmsg
    exit 0

    output:

    # dmesg -c
    ...
    # ./test_app
    # dmesg
    Bluetooth: Bluetooth Driver for TI WiLink - Version 1.0
    hdev c20ab000
    HCI device registered (hdev c20ab000)
    hci0 c20ab000
    (stc): st_register(4) 
    (stc):  chnl_id list empty :4 
    (stk) : st_kim_startBT_MODULE_READY TO APP
    DEBUG: failed hci_get_route - errno = 19
    DEBUG: route = -1
    DEBUG: devid = 118
    (stk) :ldisc_install = 1
    (stc): st_tty_open 
    (stk) :line discipline installed
    (stk) :TIInit_8.6.15.bts
    (stk) :ldisc_install = 2   #Note I added this in the kernel for debugging
    (stc): add_channel_to_table: id 4
    (stc): st_register(2) 
    (stc): add_channel_to_table: id 2
    (stc): st_register(3) 
    (stc): add_channel_to_table: id 3
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 4
    hci0: type 1 len 5
    hci0: type 1 len 6
    hci0: type 1 len 11
    hci0: type 1 len 12
    hci0: type 1 len 4
    hci0: type 1 len 5
    hci0: type 1 len 5
    hci0: type 1 len 4
    hci0: type 1 len 5
    hci0: type 1 len 6
    hci0: type 1 len 6
    #

    And as a clarification, I'm looking for an event that notifies me when the stack init commands are complete, so that hci_get_route will not fail.

  • Changing the line:

    hciconfig up > /dev/null

    to specify the interface:

    hciconfig hci0 up > /dev/null

    Seems to resolve my issue of the script exiting before the stack is ready (by exiting I mean the "system" call returning).

    It would still be nice to have some sort of signal though. If there really is none, let me know and I will mark this as the answer.

  • Hi,

    The "hciconfig hci0 up" would send the HCIDEVUP icotl to the bluetooth socket (blocking). This in turn calls hci_dev_open() which interacts with the shared transport and turns the device up.

    This is actually a blocking call - so it returns once the BT is turned on. So a separate signal to the userspace is not required.

    Regards,
    Gigi Joseph.
  • Great. Thank you for your response.