13 Replies Latest reply on May 27, 2015 8:20 AM by JPMontero_Intel

    Bluetooth service error

    Ruscoff

      Hi all,

         I'm using bluetooth RFCOMM SPP with android phone, it works very well with new yocto beta release.

       

      Sometime it gone mad, socket accept return always  -1 with EBADFD

      client = accept(s, (struct sockaddr *)&rem_addr, &opt);
      

       

      I'm trying to rfkill block and unblock bluetooth, but error persist.

       

      I try also to restart bluetooth service, but it shows this error, maybe is this the problem?

       

      ● bluetooth.service - Bluetooth service

         Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)

         Active: active (running) since Sat 2015-03-14 10:08:14 UTC; 3min 32s ago

           Docs: man:bluetoothd(8)

      Main PID: 1013 (bluetoothd)

         Status: "Running"

         CGroup: /system.slice/bluetooth.service

                 └─1013 /usr/lib/bluez5/bluetooth/bluetoothd

       

       

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Bluetooth daemon 5.24

      Mar 14 10:08:14 dispUno systemd[1]: Started Bluetooth service.

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Starting SDP server

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Bluetooth management interface 1.3 initialized

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Sap driver initialization failed.

      Mar 14 10:08:14 dispUno bluetoothd[1013]: sap-server: Operation not permitted (1)

      Mar 14 10:08:14 dispUno bluetoothd[1013]: hci0 Load Connection Parameters failed: Unknown Command (0x01)

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Endpoint registered: sender=:1.6 path=/MediaEndpoint/A2DPSource

      Mar 14 10:08:14 dispUno bluetoothd[1013]: Endpoint registered: sender=:1.6 path=/MediaEndpoint/A2DPSink

        • 1. Re: Bluetooth service error
          Ruscoff

          Add some information:

           

          The true problem is this:

          struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
            char buf[1024] = { 0 };
            int s, client, bytes_read;
            socklen_t opt = sizeof(rem_addr);
          
          
            s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
          
          
            char src[18] = "00:00:00:00:00:00";
          
          
            str2ba(src, &loc_addr.rc_bdaddr);
            loc_addr.rc_family = AF_BLUETOOTH;
            //loc_addr.rc_bdaddr = *BDADDR_ANY;
            loc_addr.rc_channel = (uint8_t) 1;
            if(bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr))< 0 )
            {
            cout << "BT Socket Bind errno: " << errno << endl;
            close(s);
            sleep(1);
            continue;
            }
          
          

           

          Bind function return ERRNO=98 : Address already in use.

           

          How can i resolve this? some system call ?

           

          Thanks

          • 2. Re: Bluetooth service error
            JPMontero_Intel

            Hi Ruscoff

             

            Have you tried restarting the service or changing the address? This error is caused when there is another process already using that port. Another option would be to change the Port or to reinitialize the Bluetooth service.

             

            Regards,
            JPMontero_Intel

            • 3. Re: Bluetooth service error
              Ruscoff

              I try many ways:

              - stop and start bluetooth.service

              - block and unblock rfkill

              - try with rc_channel = 0

               

              Could you show me how to change port?

               

              Can i use netstat for search open port?

               

              Thanks

              • 4. Re: Bluetooth service error
                Ruscoff

                This is my /proc/net/rfcomm status when show error:

                 

                root@dispUno:/proc/314/net# cat rfcomm
                sk              RefCnt Rmem  Wmem  User  Inode  Src Dst Parent
                f527a800 2      0      0      0      370698 98:4f:ee:03:0d:00 00:00:46:65:72:01 0
                f532f800 2      0      0      0      370697 00:00:00:00:00:00 00:00:00:00:00:00 0
                

                 

                And this is process:

                root@dispUno:/proc/314/net# ps
                  PID USER       VSZ STAT COMMAND
                    1 root     12716 S    {systemd} /sbin/init
                    2 root         0 SW   [kthreadd]
                    3 root         0 SW   [ksoftirqd/0]
                    5 root         0 SW<  [kworker/0:0H]
                    7 root         0 SW   [migration/0]
                    8 root         0 SW   [rcu_preempt]
                    9 root         0 SW   [rcu_bh]
                   10 root         0 SW   [rcu_sched]
                   11 root         0 SW   [watchdog/0]
                   12 root         0 SW   [watchdog/1]
                   13 root         0 SW   [migration/1]
                   14 root         0 SW   [ksoftirqd/1]
                   16 root         0 SW<  [kworker/1:0H]
                   17 root         0 SW<  [khelper]
                   18 root         0 SW   [kdevtmpfs]
                   19 root         0 SW<  [netns]
                   20 root         0 SW<  [writeback]
                   21 root         0 SW<  [bioset]
                   22 root         0 SW<  [kblockd]
                   23 root         0 SW   [khubd]
                   25 root         0 SW<  [devfreq_wq]
                   27 root         0 SW<  [cfg80211]
                   28 root         0 SW   [irq/47-intel_ps]
                   29 root         0 SW<  [rpciod]
                   30 root         0 SW   [irq/50-adc]
                   43 root         0 SW   [khungtaskd]
                   44 root         0 SW   [kswapd0]
                   45 root         0 SW   [fsnotify_mark]
                   46 root         0 SW<  [nfsiod]
                   47 root         0 SW<  [crypto]
                   60 root         0 SW<  [kthrotld]
                   61 root         0 SW<  [hsu_bt_port_p]
                   62 root         0 SW<  [hsu_uart1_port_]
                   63 root         0 SW<  [hsu_uart2_port_]
                   65 root         0 SW   [irq/27-i2c_pmic]
                   66 root         0 SW   [irq/52-bcove_th]
                   67 root         0 SW   [irq/1-soc_thrm]
                   69 root         0 SW   [mmcqd/0]
                   70 root         0 SW   [mmcqd/0boot0]
                   71 root         0 SW   [mmcqd/0boot1]
                   72 root         0 SW   [mmcqd/0rpmb]
                   73 root         0 SW<  [kworker/0:1H]
                   74 root         0 SW<  [kworker/1:1H]
                   75 root         0 SW<  [sst_mad_wq]
                   76 root         0 SW<  [sst_post_msg_wq]
                   77 root         0 SW   [irq/24-intel_ss]
                   78 root         0 SW<  [krfcommd]
                   79 root         0 SW<  [deferwq]
                   81 root         0 SW<  [intel_mid_ssp_s]
                   82 root         0 SW<  [0000:00:07.0]
                   83 root         0 SW<  [intel_mid_ssp_s]
                   84 root         0 SW<  [0000:00:07.1]
                   85 root         0 SW<  [intel_mid_ssp_s]
                   86 root         0 SW<  [0000:00:07.2]
                   88 root         0 SW   [irq/27-pmic_ccs]
                   90 root         0 SW   [irq/30-msic_pow]
                   91 root         0 SW   [jbd2/mmcblk0p8-]
                   92 root         0 SW<  [ext4-dio-unwrit]
                  105 root      8768 S    /lib/systemd/systemd-journald
                  126 root         0 SW   [file-storage]
                  127 root         0 SW   [otg]
                  138 root      9468 S    /lib/systemd/systemd-udevd
                  168 systemd- 12152 S    /lib/systemd/systemd-timesyncd
                  180 root         0 SW<  [ext4-dio-unwrit]
                  189 root         0 SW   [jbd2/mmcblk0p10]
                  190 root         0 SW<  [ext4-dio-unwrit]
                  214 root         0 SW   [scsi_eh_1]
                  215 root         0 SW   [usb-storage]
                  236 root      2440 S    /usr/bin/watchdog-sample 30
                  237 root      1788 S    /usr/bin/pwr_button_handler /bin/systemctl start bli
                  240 root      3280 S    /usr/sbin/bluetooth_rfkill_event
                  241 root      2404 S    {xdk-daemon} /bin/sh /opt/xdk-daemon/xdk-daemon
                  254 root      2404 S    {launcher.sh} /bin/sh /opt/edison/launcher.sh
                  255 root     36272 S    /usr/bin/node /opt/xdk-daemon/main.js
                  259 root      1984 S    /opt/edison/clloader --escape --binary --zmodem --di
                  263 messageb  3012 S    /usr/bin/dbus-daemon --system --address=systemd: --n
                  274 root      2732 S    /lib/systemd/systemd-networkd
                  275 root      2672 S    /lib/systemd/systemd-logind
                  289 nobody    2840 S    /usr/sbin/mdnsd
                  291 root      4688 S    /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
                  292 root         0 SW<  [kworker/u5:0]
                  293 root         0 SW<  [hci0]
                  294 root         0 SW<  [hci0]
                  297 root      1796 S    brcm_patchram_plus --use_baudrate_for_download --no2
                  314 root      2644 S    -sh
                  315 root      2192 S    /sbin/agetty --noclear tty1 linux
                  317 pulse    99.9m S <  /usr/bin/pulseaudio --system --resample-method=src-s
                  318 root     72528 S    /usr/bin/node /opt/xdk-daemon/current/appDaemon.js
                  344 root      2436 S    /lib/systemd/systemd-hostnamed
                  345 root      2404 S    /bin/sh -c node /usr/lib/edison_config_tools/edison-
                  346 root     37504 S    node /usr/lib/edison_config_tools/edison-config-serv
                  348 root      2184 S    /lib/systemd/systemd-resolved
                  442 root         0 SW   [kworker/u4:1]
                  450 root      2388 S    /lib/systemd/systemd-timedated
                 6417 root         0 SW   [wl_event_handle]
                 6418 root         0 SW   [dhd_watchdog_th]
                 6419 root         0 SW   [dhd_dpc]
                 6424 root      5656 S    /usr/sbin/hostapd /etc/hostapd/hostapd.conf
                 6430 root      2404 S    /usr/sbin/udhcpd -f -S /etc/hostapd/udhcpd-for-hosta
                 6449 root         0 SW   [kworker/0:2]
                 6532 root         0 SW   [kworker/1:2]
                 7586 root         0 SW<  [kworker/u5:2]
                 7598 root      4740 S    /usr/lib/bluez5/bluetooth/bluetoothd --noplugin=sap
                 8210 root         0 SW   [kworker/0:1]
                 8216 root      2644 R    ps
                11138 root         0 SW   [kworker/0:0]
                22804 root      2404 S <  udhcpc -i wlan0
                22809 root      2404 S <  udhcpc -i wlan0
                29237 root         0 SW   [kworker/u4:2]
                32532 root         0 SW   [kworker/1:0]
                

                 

                I'm pretty sure that mine process is shutdown but if i try to restart it, it shown Address already in use.

                • 5. Re: Bluetooth service error
                  JPMontero_Intel

                  Hi Ruscoff,

                   

                  Thank you for the extra information. Let me investigate further to see what else I can find on this.

                   

                  Regards,
                  JPMontero_Intel

                  • 6. Re: Bluetooth service error
                    Ruscoff

                    Thanks JPMontero, please let me know if you find something, it's very important for my project, actualy i can only reboot system to resolve.

                     

                    In my opinion, seems the bluetooth kernel sometimes doesn't release socket after close, like a very long TIME_WAIT. However i tried to wait 20 minutes but nothing happens.

                     

                    Some Another infos:

                        

                       -  My bluetooth connections are between edison and an android phone.

                       -  I tried to connect and disconnect phone from edison many times (10-20), it works correctly. Actually i'm not able to understand why it happens, but i think that when phone app crash or something strange happens, the socket isn't release correctly and showing me address already in use.

                       - i tried with rc_channel = 0.  Address already in use was not happen howewer bluetooth couldn't accept any connection without send any warning or error. I tried also with SO_REUSESOCKET but it behaves like rc_channel = 0. 

                     

                    Do you know if are there way to reload bluetooth driver without reboot system?


                    Thanks

                     

                    • 7. Re: Bluetooth service error
                      Intel_Luis

                      Hi Ruscoff,

                       

                      I saw in your other reply that you have two connections, one of them should be your Edison and the second one should be your app. When your app crashes, the connection is not closed. Have you tried restarting the bluetooth-rfkill-event.service? Take a look at the following output.

                       

                      root@edison:/proc/601/net# cat rfcomm
                      sk              RefCnt Rmem  Wmem  User  Inode  Src Dst Parent
                      f54fc800 2      0      0      0      22109  98:4f:ee:01:fc:b0 a0:b4:a5:1e:27:c5 0
                      f54ff400 2      0      0      0      22890  98:4f:ee:01:fc:b0 00:00:00:00:00:00 0
                      

                       

                      root@edison:/proc/601/net# systemctl restart bluetooth-rfkill-event.service
                      

                       

                      root@edison:/proc/601/net# cat rfcomm
                      sk              RefCnt Rmem  Wmem  User  Inode  Src Dst Parent
                      f54fc800 2      0      0      0      22109  98:4f:ee:01:fc:b0 a0:b4:a5:1e:27:c5 0
                      

                       

                       

                      Regards,

                      Intel_Luis

                      • 8. Re: Bluetooth service error
                        Ruscoff

                        Thanks Luis,

                          i try and i will let you know, but i think that this is the solution.

                         

                        I see that android bluetooth socket connect function has bug in some android phone, maybe also Intel has some strange behave.

                        Sometimes, when phone try to connect radio link was correctly established in low layer, but intel server socket hasn't accept any device, so phone continues try to connect. When i force close of phone client socket intel suddenly accepts the socket but it won't be freed causing address already bind.

                        • 9. Re: Bluetooth service error
                          Ruscoff
                          1. root@edison:/proc/601/net# systemctl restart bluetooth-rfkill-event.service

                          Re: Bluetooth service error

                           

                          I try with systemctl restart bluetooth-rfkill-event.service  but it doesn't work correctly.


                          Before use this command when i type rfkill list i see:

                           

                          0: phy0: wlan

                                  Soft blocked: no

                                  Hard blocked: no

                          1: brcmfmac-wifi: wlan

                                  Soft blocked: no

                                  Hard blocked: no

                          2: bcm43xx Bluetooth: bluetooth

                                  Soft blocked: no

                                  Hard blocked: no

                          3: hci0: bluetooth

                                  Soft blocked: no

                                  Hard blocked: no

                           

                          After command, hci0 disappears blocking all bt connection:

                           

                          0: phy0: wlan

                                  Soft blocked: no

                                  Hard blocked: no

                          1: brcmfmac-wifi: wlan

                                  Soft blocked: no

                                  Hard blocked: no

                          2: bcm43xx Bluetooth: bluetooth

                                  Soft blocked: no

                                  Hard blocked: no

                          • 10. Re: Bluetooth service error
                            Intel_Luis

                            Hi Ruscoff,

                             

                            I think you need to unblock bluetooth. Take a look at the following output:

                             

                            root@edison:~# rfkill list
                            0: phy0: wlan
                                    Soft blocked: no
                                    Hard blocked: no
                            1: brcmfmac-wifi: wlan
                                    Soft blocked: no
                                    Hard blocked: no
                            2: bcm43xx Bluetooth: bluetooth
                                    Soft blocked: yes
                                    Hard blocked: no
                            
                            

                             

                            root@edison:~# rfkill block bluetooth
                            root@edison:~# rfkill unblock bluetooth
                            root@edison:~# rfkill list
                            0: phy0: wlan
                                    Soft blocked: no
                                    Hard blocked: no
                            1: brcmfmac-wifi: wlan
                                    Soft blocked: no
                                    Hard blocked: no
                            2: bcm43xx Bluetooth: bluetooth
                                    Soft blocked: no
                                    Hard blocked: no
                            3: hci0: bluetooth
                                    Soft blocked: no
                                    Hard blocked: no
                            
                            

                             

                             

                            Regards,

                            Intel_Luis

                            • 11. Re: Bluetooth service error
                              CMata_Intel

                              Hi Ruscoff

                               

                              Do you still have problems with this? Or do you have updates?

                               

                              Regards;

                              CMata

                              • 12. Re: Bluetooth service error
                                Ruscoff

                                Hi CMata,

                                 

                                With this sequence, i was able to close socket and made hci0 visible.

                                system("rfkill block bluetooth");
                                system("systemctl restart bluetooth.service");
                                system("systemctl restart bluetooth-rfkill-event.service");
                                system("rfkill unblock bluetooth");
                                

                                 

                                However, i couldn't resolve the problem. After this procedure socket bind showed address already bind yet. But this time if i close and restart software it could bind and work correctly.

                                I don't know why restarting software, it works correctly, instead during execution i can't close and restart socket.

                                • 13. Re: Bluetooth service error
                                  JPMontero_Intel

                                  Hi Ruscoff,

                                   

                                  It seems it could be that the app is not closing the socket, not the Bluetooth service. I suggest you to make some changes to the code to see if it releases the socket once the process is finished.

                                   

                                  Regards,
                                  JPMontero_Intel