2015-08-28 13:31:40

by krishnaks

[permalink] [raw]
Subject: USB BT gives problem If device plugged during boot to platform.

Hi,

I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
Bluetooth device. I referred instruction in
http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
able to build.
After botting Android image with USB dongle connected and type "hciconfig
hci0 up" on console, It is throwing following error.
Can't init device hci0: Unknown error 132 (132)

If I Type hciconfig -a . It gives following.
hci0: Type: BR/EDR Bus: USB
BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
DOWN
RX bytes:547 acl:0 sco:0 events:27 errors:0
TX bytes:384 acl:0 sco:0 commands:27 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT



But If I unplug and plug USB dongle, and then try same command (hciconfig
hci0 up), It works. Even "hcitool scan" command also working after that.

Why 1st time not working when USB dongle is connected?
Also when I check Bluez debug log in logcat.
I am getting one error log when USB dongle connected during boot.
E/bluetoothd( 841): Failed to set mode: Blocked through rfkill (0x12).

Please let me know If I missed any settings

Thanks in advance,




2015-08-31 07:13:37

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

> Hi,
>
>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
>> Bluetooth device. I referred instruction in
>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
>> able to build.
>> After botting Android image with USB dongle connected and type
>> "hciconfig
>> hci0 up" on console, It is throwing following error.
>> Can't init device hci0: Unknown error 132 (132)
>>
>> If I Type hciconfig -a . It gives following.
>> hci0: Type: BR/EDR Bus: USB
>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
>> DOWN
>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>> Link policy: RSWITCH SNIFF
>> Link mode: SLAVE ACCEPT
>>
>>
>>
>> But If I unplug and plug USB dongle, and then try same command
>> (hciconfig
>> hci0 up), It works. Even "hcitool scan" command also working after that.
>>
>> Why 1st time not working when USB dongle is connected?
>> Also when I check Bluez debug log in logcat.
>> I am getting one error log when USB dongle connected during boot.
>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill (0x12).
>
> I think that blocked through rfkill is pretty obvious. Check with the
> rfkill tool on what the current settings are. For some reason it seems
> Bluetooth is blocked by default. And I remember there were some kernel
> patches for this. Just do not remember the details.
>
> Regards
>
> Marcel
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

Hi,

Thanks for the reply.

In my busybox utils rfkill is not enabled. If I enable it and try "rfkill
unblock" is that will be enough? or I need to search for Kernel patch that
fixes this rfkill block issue?


Regards,
KP

2015-08-28 19:07:55

by Marcel Holtmann

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

Hi,

> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
> Bluetooth device. I referred instruction in
> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
> able to build.
> After botting Android image with USB dongle connected and type "hciconfig
> hci0 up" on console, It is throwing following error.
> Can't init device hci0: Unknown error 132 (132)
>
> If I Type hciconfig -a . It gives following.
> hci0: Type: BR/EDR Bus: USB
> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
> DOWN
> RX bytes:547 acl:0 sco:0 events:27 errors:0
> TX bytes:384 acl:0 sco:0 commands:27 errors:0
> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
> Link policy: RSWITCH SNIFF
> Link mode: SLAVE ACCEPT
>
>
>
> But If I unplug and plug USB dongle, and then try same command (hciconfig
> hci0 up), It works. Even "hcitool scan" command also working after that.
>
> Why 1st time not working when USB dongle is connected?
> Also when I check Bluez debug log in logcat.
> I am getting one error log when USB dongle connected during boot.
> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill (0x12).

I think that blocked through rfkill is pretty obvious. Check with the rfkill tool on what the current settings are. For some reason it seems Bluetooth is blocked by default. And I remember there were some kernel patches for this. Just do not remember the details.

Regards

Marcel


2015-09-21 11:02:49

by Szymon Janc

[permalink] [raw]
Subject: Re: GATT onWriteCharacteristic() returns status=1 (BT_STATUS_FAIL)

Hi,

On Monday 21 of September 2015 06:43:20 [email protected] wrote:
> Hi,
>
> I am using Bluez 5.33 on Android kitkat 4.4.3.
> I am testing GATT functionality and I found that sometime
> onWriteCharacteristic returns status 1 (BT_STATUS_FAIL). In android
> Application I am checking for success status (i.e. 0) which I am getting
> most of the time. But occasionally I am getting Status 1 because of which
> my application logic is failing.
>
> When Bluez will send Status 1 and on what basis? How to avoid this?
>
>
> -----------------------Working Log-------------------------------
> D/BluetoothGatt( 1359): writeCharacteristic() - uuid:
> 1d4de0a0-9f84-11e4-a042-0002a5d5c51b
> D/BtGatt.GattService( 1259): writeCharacteristic() -
> address=00:00:39:36:85:2F
> D/BtGatt.GattService( 1259): onWriteCharacteristic() -
> address=00:00:39:36:85:2F, status=0
> D/BluetoothGatt( 1359): onCharacteristicWrite() - Device=00:00:39:36:85:2F
> UUID=1d4de0a0-9f84-11e4-a042-0002a5d5c51b Status=0
> ----------------------Log End-------------------------
>
>
> --------------------------Failure Log---------------------------------
> D/BluetoothGatt( 1359): writeCharacteristic() - uuid:
> 1d4de0a0-9f84-11e4-a042-0002a5d5c51b
> D/BtGatt.GattService( 1259): writeCharacteristic() -
> address=00:00:39:36:85:2F
> D/BtGatt.GattService( 1259): onWriteCharacteristic() -
> address=00:00:39:36:85:2F, status=1
> D/BluetoothGatt( 1359): onCharacteristicWrite() - Device=00:00:39:36:85:2F
> UUID=1d4de0a0-9f84-11e4-a042-0002a5d5c51b Status=1
> --------------------------Log End-------------------------------

Please enable debug logs for daemon (check android/README for how-to) and
provide both debug logs and btmon HCI traces.

--
BR
Szymon Janc

2015-09-21 10:43:20

by krishnaks

[permalink] [raw]
Subject: GATT onWriteCharacteristic() returns status=1 (BT_STATUS_FAIL)

Hi,

I am using Bluez 5.33 on Android kitkat 4.4.3.
I am testing GATT functionality and I found that sometime
onWriteCharacteristic returns status 1 (BT_STATUS_FAIL). In android
Application I am checking for success status (i.e. 0) which I am getting
most of the time. But occasionally I am getting Status 1 because of which
my application logic is failing.

When Bluez will send Status 1 and on what basis? How to avoid this?


-----------------------Working Log-------------------------------
D/BluetoothGatt( 1359): writeCharacteristic() - uuid:
1d4de0a0-9f84-11e4-a042-0002a5d5c51b
D/BtGatt.GattService( 1259): writeCharacteristic() -
address=00:00:39:36:85:2F
D/BtGatt.GattService( 1259): onWriteCharacteristic() -
address=00:00:39:36:85:2F, status=0
D/BluetoothGatt( 1359): onCharacteristicWrite() - Device=00:00:39:36:85:2F
UUID=1d4de0a0-9f84-11e4-a042-0002a5d5c51b Status=0
----------------------Log End-------------------------


--------------------------Failure Log---------------------------------
D/BluetoothGatt( 1359): writeCharacteristic() - uuid:
1d4de0a0-9f84-11e4-a042-0002a5d5c51b
D/BtGatt.GattService( 1259): writeCharacteristic() -
address=00:00:39:36:85:2F
D/BtGatt.GattService( 1259): onWriteCharacteristic() -
address=00:00:39:36:85:2F, status=1
D/BluetoothGatt( 1359): onCharacteristicWrite() - Device=00:00:39:36:85:2F
UUID=1d4de0a0-9f84-11e4-a042-0002a5d5c51b Status=1
--------------------------Log End-------------------------------

Regards,
KP


2015-09-12 10:21:44

by Marcel Holtmann

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

Hi,

>> I just checked BT enable flow from android and found that
>> When USB BT Dongle is not connected during bootm,During Bluez Init
>> (hal-bluetooth.c:init()), hal_ipc_accept is failing.
>> I hope IPC is failing as USB BT dongle is not connected.
>>
>> From below Logcat suggests that
>> E/BlueZ ( 799): bluetoothd connect timeout
>> E/BluetoothServiceJni( 799): Error while setting the callbacks
>> E/BluetoothAdapterState( 799): Error while turning Bluetooth On
>>
>> because of this none of the BT interfaces are initialized.
>>
>> When we connect the USB BT dongle , hal-bluetooth.c:init() is not getting
>> called. because of this BT enable is failing.
>>
>>
>> But in working case (USB BT dongle connected during boot). Each time when
>> we connect BT dongle, init is getting called.
>>
>> I also observed that If I remove the USB dongle without turning off BT
>> from android BT settings menu, at that time
>> also init is not getting called and because of that BT will not get
>> enabled properly.
>>
>> If we make "init" function to call whenever BT dongle it connected, is
>> that will be enough for BT HAL module to work
>> properly or any other settings might be required?
>>
>
> I have added call to init and get_profile_interface function in Android
> JNI in enable Function so that we can initialize the BT HAL.
> With this change BT is turning on even if I connect the dongle after Boot.
>
> Thanks for the support.
>
> I observed one more issue when I connect different USB dongle. Was getting
> "Bluetooth address mismatch" error as in cache previous connected USB BT
> hardware address is saved.
>
> Is that check required? After bypassing that check, BT is working with
> different USB dongle also.

for a lot of Bluetooth controllers we have support for Set Public Address management command. If the kernel driver provides the vendor specific hdev->set_bdaddr callback, then in theory you can have BlueZ for Android programming the address into the controller even if you swap it out.

If you do that, then you would not see this message. However that is just how Android handles things and we have to deal with it. Feel free to send patches to start supporting Set Public Address handling.

Regards

Marcel



2015-09-11 12:18:05

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

>> Hi,
>>
>> On Tuesday 08 of September 2015 10:09:10 [email protected]
>> wrote:
>>> > Hi,
>>> >
>>> > On Tuesday 08 of September 2015 09:04:18 [email protected]
>>> wrote:
>>> >> >>> Hi,
>>> >> >>>
>>> >> >>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB
>>> >>
>>> >> based
>>> >>
>>> >> >>>> Bluetooth device. I referred instruction in
>>> >> >>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README
>>> >>
>>> >> and
>>> >>
>>> >> >>>> able to build.
>>> >> >>>> After botting Android image with USB dongle connected and type
>>> >> >>>> "hciconfig
>>> >> >>>> hci0 up" on console, It is throwing following error.
>>> >> >>>> Can't init device hci0: Unknown error 132 (132)
>>> >> >>>>
>>> >> >>>> If I Type hciconfig -a . It gives following.
>>> >> >>>> hci0: Type: BR/EDR Bus: USB
>>> >> >>>>
>>> >> >>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU:
>>> >> 64:1
>>> >>
>>> >> >>>> DOWN
>>> >> >>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>>> >> >>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>>> >> >>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>>> >> >>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>>> >> >>>> Link policy: RSWITCH SNIFF
>>> >> >>>> Link mode: SLAVE ACCEPT
>>> >> >>>>
>>> >> >>>> But If I unplug and plug USB dongle, and then try same command
>>> >> >>>> (hciconfig
>>> >> >>>> hci0 up), It works. Even "hcitool scan" command also working
>>> after
>>> >> >>>> that.
>>> >> >>>>
>>> >> >>>> Why 1st time not working when USB dongle is connected?
>>> >> >>>> Also when I check Bluez debug log in logcat.
>>> >> >>>> I am getting one error log when USB dongle connected during
>>> boot.
>>> >> >>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
>>> >> >>>> (0x12).
>>> >> >>>
>>> >> >>> I think that blocked through rfkill is pretty obvious. Check
>>> with
>>> >>
>>> >> the
>>> >>
>>> >> >>> rfkill tool on what the current settings are. For some reason it
>>> >>
>>> >> seems
>>> >>
>>> >> >>> Bluetooth is blocked by default. And I remember there were some
>>> >>
>>> >> kernel
>>> >>
>>> >> >>> patches for this. Just do not remember the details.
>>> >> >>>
>>> >> >>> Regards
>>> >> >>>
>>> >> >>> Marcel
>>> >> >>>
>>> >> >>> --
>>> >> >>> To unsubscribe from this list: send the line "unsubscribe
>>> >> >>> linux-bluetooth"
>>> >> >>> in
>>> >> >>> the body of a message to [email protected]
>>> >> >>> More majordomo info at
>>> http://vger.kernel.org/majordomo-info.html
>>> >> >>
>>> >> >> Hi,
>>> >> >>
>>> >> >> Thanks for the reply.
>>> >> >>
>>> >> >> In my busybox utils rfkill is not enabled. If I enable it and try
>>> >> >> "rfkill
>>> >> >> unblock" is that will be enough? or I need to search for Kernel
>>> patch
>>> >> >> that
>>> >> >> fixes this rfkill block issue?
>>> >> >
>>> >> > Hi,
>>> >> >
>>> >> > By Analysing I found 3 scenarios and only in one scenario BT is
>>> >>
>>> >> working.
>>> >>
>>> >> > Scenario 1 : Connect USB BT Dongle and then boot the android
>>> >>
>>> >> device.Then
>>> >>
>>> >> > Turn on from Android Bluetooth settings
>>> >> >
>>> >> > Result: Not working. Rfkill block error.
>>> >> > E/bluetoothd( 868): Failed to set mode: Blocked through rfkill
>>> (0x12)
>>> >> >
>>> >> > Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug
>>> >>
>>> >> again.
>>> >>
>>> >> > Then Turn on from Android Bluetooth settings.
>>> >> >
>>> >> > Result: Working: BT turning on and scanning BT/BLE devices.
>>> >> >
>>> >> > Scenario 3: Boot Android device and then plug the USB BT
>>> Dongle.Then
>>> >>
>>> >> Turn
>>> >>
>>> >> > on from Android Bluetooth settings.
>>> >> >
>>> >> > Result: Not working. Here we are not getting any debug prints from
>>> >>
>>> >> bluez.
>>> >>
>>> >> > Whether we need to rerun the init.bluetooth.rc as BT Dongle was
>>> not
>>> >> > connected during boot.
>>> >> > From Logcat,observing following error messages
>>> >> >
>>> >> > IBluetooth.configHciSnoopLog return false
>>> >> > Bluetooth module is not loaded
>>> >> >
>>> >> > Logcat:
>>> >> >
>>> >> > -------------------Start-------------------
>>> >> > D/BluetoothManagerService( 543): enable(): mBluetooth =null
>>> mBinding
>>> >>
>>> >> =
>>> >>
>>> >> > false
>>> >> > D/BluetoothManagerService( 543): Message: 1
>>> >> > D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth =
>>> null
>>> >> > D/BluetoothAdapterService( 1032): REFCOUNT: CREATED.
>>> INSTANCE_COUNT2
>>> >> > D/BluetoothAdapterState( 1032): make
>>> >> > I/BluetoothAdapterState( 1032): Entering OffState
>>> >> > D/BluetoothManagerService( 543): BluetoothServiceConnection:
>>> >> > com.android.bluetooth.btservice.AdapterService
>>> >> > D/BluetoothManagerService( 543): Message: 40
>>> >>
>>> >> > D/BluetoothManagerService( 543):
>>> MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
>>> >> 1
>>> >>
>>> >> > E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog
>>> return
>>> >> > false
>>> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceUp
>>> >>
>>> >> callbacks
>>> >>
>>> >> > D/BluetoothManagerService( 543): Broadcasting
>>> onBluetoothServiceUp()
>>> >>
>>> >> to 5
>>> >>
>>> >> > receivers.
>>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>>> >>
>>> >> USER_TURN_ON
>>> >>
>>> >> > D/BluetoothAdapterProperties( 1032): Setting state to 11
>>> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed:
>>> 10->
>>> >>
>>> >> 11
>>> >>
>>> >> > D/BluetoothAdapterService( 1032): Broadcasting
>>> updateAdapterState()
>>> to
>>> >>
>>> >> 1
>>> >>
>>> >> > receivers.
>>> >> > D/BluetoothManagerService( 543): Message: 60
>>> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>>> >> > prevState = 10, newState=11
>>> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent:
>>> 10
>>> ->
>>> >>
>>> >> 11
>>> >>
>>> >> > D/BluetoothBondStateMachine( 1032): make
>>> >> > D/BluetoothMapService( 1032): onReceive
>>> >> > I/BluetoothBondStateMachine( 1032): StableState(): Entering Off
>>> State
>>> >> > D/HeadsetService( 1032): Received start request. Starting
>>> profile...
>>> >> > D/HeadsetStateMachine( 1032): make
>>> >> > E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not
>>> loaded
>>> >> > D/A2dpService( 1032): Received start request. Starting profile...
>>> >> > V/Avrcp ( 1032): make
>>> >> > E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
>>> >> > D/A2dpStateMachine( 1032): make
>>> >> > E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
>>> >> > D/A2dpStateMachine( 1032): Enter Disconnected: -2
>>> >> > D/HidService( 1032): Received start request. Starting profile...
>>> >> > E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
>>> >> > D/HealthService( 1032): Received start request. Starting
>>> profile...
>>> >> > I/BluetoothAdapterState( 1032): Entering PendingCommandState
>>> State:
>>> >> > isTurningOn()=true, isTurningOff()=false
>>> >> > E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.hdp.HealthService
>>> >> > D/PanService( 1032): Received start request. Starting profile...
>>> >> > D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
>>> >> > E/BluetoothPanServiceJni( 1032): ## ERROR :
>>> initializeNative(L115):
>>> >> > Bluetooth module is not loaded##
>>> >> > D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
>>> >> > E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
>>> >> > D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
>>> >> > D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0
>>> >>
>>> >> mSignal=0
>>> >>
>>> >> > mRoam=0 mBatteryCharge=5
>>> >> > D/BtGatt.GattService( 1032): Received start request. Starting
>>> >>
>>> >> profile...
>>> >>
>>> >> > D/BtGatt.GattService( 1032): start()
>>> >> > E/BtGatt.JNI( 1032): ERROR: void
>>> android::initializeNative(JNIEnv*,
>>> >> > jobject)(L694): Bluetooth module is not loaded##
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.hdp.HealthService
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.hdp.HealthService
>>> >> > D/BluetoothMapService( 1032): Received start request. Starting
>>> >>
>>> >> profile...
>>> >>
>>> >> > D/BluetoothMapService( 1032): start()
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.map.BluetoothMapService
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.map.BluetoothMapService
>>> >> > D/BluetoothAdapterService( 1032): Profile still not
>>> >> > running:com.android.bluetooth.map.BluetoothMapService
>>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE =
>>> >>
>>> >> STARTED,
>>> >>
>>> >> > isTurningOn=true, isTurningOff=false
>>> >> > E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
>>> >> > D/BluetoothAdapterProperties( 1032): Setting state to 10
>>> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed:
>>> 11->
>>> >>
>>> >> 10
>>> >>
>>> >> > D/BluetoothAdapterService( 1032): Broadcasting
>>> updateAdapterState()
>>> to
>>> >>
>>> >> 1
>>> >>
>>> >> > receivers.
>>> >> > I/BluetoothAdapterState( 1032): Entering OffState
>>> >> > D/BluetoothManagerService( 543): Message: 60
>>> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>>> >> > prevState = 11, newState=10
>>> >> > D/BluetoothManagerService( 543): Broadcasting
>>> >> > onBluetoothStateChange(false) to 10 receivers.
>>> >> > D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
>>> >> > D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
>>> >> > D/BluetoothPbap( 851): onBluetoothStateChange: up=false
>>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>>> >> > D/BluetoothMap( 851): onBluetoothStateChange: up=false
>>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>>> >> > D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
>>> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent:
>>> 11
>>> ->
>>> >>
>>> >> 10
>>> >>
>>> >> > E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
>>> >> > D/BluetoothMapService( 1032): onReceive
>>> >> > D/DockEventReceiver( 851): finishStartingService: stopping
>>> service
>>> >> > W/ContextImpl( 851): Calling a method in the system process
>>> without a
>>> >> > qualified user: android.app.ContextImpl.startService:1487
>>> >> > android.content.ContextWrapper.startService:494
>>> >> > android.content.ContextWrapper.startService:494
>>> >> > com.android.settings.bluetooth.DockEventReceiver.beginStartingService:1
>>> >> > 34
>>> >> > com.android.settings.bluetooth.DockEventReceiver.onReceive:115
>>> >> > D/BluetoothManagerService( 543): Sending off request.
>>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>>> >>
>>> >> USER_TURN_OFF
>>> >>
>>> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceDown
>>> >>
>>> >> callbacks
>>> >>
>>> >> > D/BluetoothManagerService( 543): Broadcasting
>>> >>
>>> >> onBluetoothServiceDown() to
>>> >>
>>> >> > 5 receivers.
>>> >> > D/BluetoothAdapterService( 1032): Cleaning up adapter native....
>>> >> > D/BluetoothAdapterService( 1032): Done cleaning up adapter
>>> native....
>>> >> > D/BluetoothAdapterService(746876560)( 1032):
>>> ****onDestroy()********
>>> >> >
>>> >> > -------------------End---------------------
>>> >> >
>>> >> > For Scenario 1 , I am trying to build rfkill tool for
>>> >>
>>> >> android(Currently no
>>> >>
>>> >> > success). Can we change the state from code by opening rfkill path
>>> >> > "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
>>> >> >
>>> >> > But scenario 3 looks like I missed some configuration.
>>> >> >
>>> >> > What could be the problem?
>>> >> >
>>> >> > Regards,
>>> >> > KP
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > To unsubscribe from this list: send the line "unsubscribe
>>> >>
>>> >> linux-bluetooth"
>>> >>
>>> >> > in
>>> >> > the body of a message to [email protected]
>>> >> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>>> >>
>>> >> Hi All,
>>> >>
>>> >>
>>> >> I analysed the Android flow and found that Android System server
>>> will
>>> >> initialize and check for bluetooth hardware on during Boot. So if we
>>> >> connect the USB BT Dongle after boot Android BT service may not
>>> identify
>>> >> it.
>>> >> May be this is the reason because of which scenario 3 (Boot Android
>>> >> device
>>> >> and then plug the USB BT Dongle.Then Turn on from Bluetooth setting)
>>> is
>>> >> not working.
>>> >> This is my understanding. Correct me If I am wrong.
>>> >>
>>> >> Anyone tried USB BT pnp on android?
>>> >
>>> > This should work but you need to load modules on boot (or have all
>>> > compiled
>>> > into kernel).
>>> >
>>> > --
>>> > BR
>>> > Szymon Janc
>>>
>>> Hi Szymon,
>>>
>>> Bluez module is loading on boot. Some initial Bluez debug prints are
>>> coming. like following logs which are coming initially
>>>
>>> -------------------------Log start---------
>>> D/BlueZ ( 183):
>>> external/bluetooth/bluez/android/hal-audio.c:audio_open()
>>> D/BlueZ ( 183):
>>> external/bluetooth/bluez/android/hal-audio.c:audio_ipc_init()
>>> D/BlueZ ( 183):
>>> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() D/BlueZ (
>>> 183):
>>> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() Waiting for
>>> connection ...
>>> E/BlueZ ( 183): APTX: failed to open library libbt-aptx.so (dlopen
>>> failed: library "libbt-aptx.so" not found)
>>> D/BlueZ ( 183):
>>> external/bluetooth/bluez/android/hal-audio.c:audio_init_check()
>>> D/BlueZ ( 183):
>>> external/bluetooth/bluez/android/hal-audio.c:audio_set_master_volume()
>>> --------------------------Log end---------------
>>> But after that bluez function calls like
>>> open_bluetooth,get_bluetooth_interface,init are getting called after
>>> boot_completed signal received android, Its calling BluetoothMapService
>>> and from there call is going to bluez over JNI.
>>>
>>> Below Log suggests that.
>>> ------------------------Logcat start------------------------
>>>
>>> D/BluetoothManagerService( 531): Retrieving Bluetooth Adapter name and
>>> address...
>>> D/BluetoothManagerService( 531): getNameAndAddress(): mBluetooth =
>>> null
>>> mBinding = false
>>> D/BluetoothManagerService( 531): Message: 200
>>> D/BluetoothManagerService( 531): MESSAGE_GET_NAME_AND_ADDRESS
>>> D/BluetoothManagerService( 531): Binding to service to get name and
>>> address
>>> I/ActivityManager( 531): Start proc com.android.bluetooth for service
>>> com.android.bluetooth/.btservice.AdapterService: pid=1037 uid=1002
>>> gids={41002, 3003, 3002, 3001, 1028, 1015, 3005, 1016, 3008}
>>> D/BluetoothManagerService( 531): Message: 30
>>> D/BluetoothManagerService( 531): Message: 30
>>> W/ContextImpl( 531): Calling a method in the system process without a
>>> qualified user: android.app.ContextImpl.bindService:1551
>>> android.bluetooth.BluetoothHeadset.doBind:283
>>> android.bluetooth.BluetoothHeadset.<init>:276
>>> android.bluetooth.BluetoothAdapter.getProfileProxy:1361
>>> android.media.AudioService.getBluetoothHeadset:2255
>>> W/ContextImpl( 531): Calling a method in the system process without a
>>> qualified user: android.app.ContextImpl.bindService:1551
>>> android.bluetooth.BluetoothA2dp.doBind:165
>>> android.bluetooth.BluetoothA2dp.<init>:158
>>> android.bluetooth.BluetoothAdapter.getProfileProxy:1364
>>> android.media.AudioService$AudioServiceBroadcastReceiver.onReceive:4176
>>> V/WiredAccessoryManager( 531): init()
>>> W/WiredAccessoryManager( 531): /sys/class/switch/usb_audio/state not
>>> found while attempting to determine initial switch state
>>> I/PowerManagerService( 531): Boot animation finished.
>>> I/Choreographer( 915): Skipped 148 frames! The application may be
>>> doing
>>> too much work on its main thread.
>>> I/dalvikvm( 1037): DexOpt: mismatch dep signature for
>>> '/system/framework/framework.odex'
>>> E/dalvikvm( 1037): /system/framework/javax.obex.jar odex has stale
>>> dependencies
>>> I/dalvikvm( 1037): DexOpt: mismatch dep name:
>>> '/data/dalvik-cache/system@[email protected]@classes.dex'
>>> vs.
>>> '/system/framework/telephony-common.odex'
>>> E/dalvikvm( 1037): /system/app/Bluetooth.apk odex has stale
>>> dependencies
>>> D/dalvikvm( 915): GC_CONCURRENT freed 1690K, 24% free 5645K/7408K,
>>> paused
>>> 3ms+2ms, total 25ms
>>> D/AdapterServiceConfig( 1037): Adding HeadsetService
>>> D/AdapterServiceConfig( 1037): Adding A2dpService
>>> D/AdapterServiceConfig( 1037): Adding HidService
>>> D/AdapterServiceConfig( 1037): Adding HealthService
>>> D/AdapterServiceConfig( 1037): Adding PanService
>>> D/AdapterServiceConfig( 1037): Adding GattService
>>> D/AdapterServiceConfig( 1037): Adding BluetoothMapService
>>> D/BlueZ ( 1037):
>>> external/bluetooth/bluez/android/hal-bluetooth.c:open_bluetooth()
>>> D/BlueZ ( 1037):
>>> external/bluetooth/bluez/android/hal-bluetooth.c:get_bluetooth_interface()
>>> D/BluetoothAdapterService( 1037): REFCOUNT: CREATED. INSTANCE_COUNT1
>>> D/BluetoothManagerService( 531): Message: 20
>>> D/BluetoothManagerService( 531): Added callback:
>>> android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@2ca2f3a8:true
>>> D/BluetoothAdapterState( 1037): make
>>> D/BlueZ ( 1037):
>>> external/bluetooth/bluez/android/hal-bluetooth.c:init()
>>>
>>> -------------------------End-----------------------------
>>>
>>> Android System server during init will get BT name and address and
>>> after
>>> that I did not find any other place where it checks for name/address.
>>> Correct me If I am wrong. or I am missing anything?
>>>
>>> hciconfig/hcitool is working fine if we connect BT dongle after
>>> boot.Only
>>> problem when we try to turn on BT from Android Bluetooth settings menu.
>>>
>>> Regards,
>>> KP
>>
>> I don't think Android supports BT adapter hot-plug. What I mean by that
>> is
>> during Framework tries to initialize BT subsystem (and clean it up right
>> after
>> that). If that fails (eg due to no adapter being present) it will not
>> try
>> to
>> initialize BT HAL again. So enabling BT from UI fails before even
>> calling
>> BT
>> HAL.
>>
>> If adapter is present on boot, and then you remove it and plug it again
>> it
>> should work. Yet, if adapter is changed (so that address changes) you
>> are
>> entering uncharted territories, so you may see some subtle hiccups.
>>
>> --
>> BR
>> Szymon Janc
>>
>
> Hi Szymon,
>
> Thanks for your reply.
> I just checked BT enable flow from android and found that
> When USB BT Dongle is not connected during bootm,During Bluez Init
> (hal-bluetooth.c:init()), hal_ipc_accept is failing.
> I hope IPC is failing as USB BT dongle is not connected.
>
> From below Logcat suggests that
> E/BlueZ ( 799): bluetoothd connect timeout
> E/BluetoothServiceJni( 799): Error while setting the callbacks
> E/BluetoothAdapterState( 799): Error while turning Bluetooth On
>
> because of this none of the BT interfaces are initialized.
>
> When we connect the USB BT dongle , hal-bluetooth.c:init() is not getting
> called. because of this BT enable is failing.
>
>
> But in working case (USB BT dongle connected during boot). Each time when
> we connect BT dongle, init is getting called.
>
> I also observed that If I remove the USB dongle without turning off BT
> from android BT settings menu, at that time
> also init is not getting called and because of that BT will not get
> enabled properly.
>
> If we make "init" function to call whenever BT dongle it connected, is
> that will be enough for BT HAL module to work
> properly or any other settings might be required?
>
> Regards,
> KP
>
>

I have added call to init and get_profile_interface function in Android
JNI in enable Function so that we can initialize the BT HAL.
With this change BT is turning on even if I connect the dongle after Boot.

Thanks for the support.

I observed one more issue when I connect different USB dongle. Was getting
"Bluetooth address mismatch" error as in cache previous connected USB BT
hardware address is saved.

Is that check required? After bypassing that check, BT is working with
different USB dongle also.

Regards,
KP

2015-09-09 10:58:08

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

> Hi,
>
> On Tuesday 08 of September 2015 10:09:10 [email protected] wrote:
>> > Hi,
>> >
>> > On Tuesday 08 of September 2015 09:04:18 [email protected]
>> wrote:
>> >> >>> Hi,
>> >> >>>
>> >> >>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB
>> >>
>> >> based
>> >>
>> >> >>>> Bluetooth device. I referred instruction in
>> >> >>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README
>> >>
>> >> and
>> >>
>> >> >>>> able to build.
>> >> >>>> After botting Android image with USB dongle connected and type
>> >> >>>> "hciconfig
>> >> >>>> hci0 up" on console, It is throwing following error.
>> >> >>>> Can't init device hci0: Unknown error 132 (132)
>> >> >>>>
>> >> >>>> If I Type hciconfig -a . It gives following.
>> >> >>>> hci0: Type: BR/EDR Bus: USB
>> >> >>>>
>> >> >>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU:
>> >> 64:1
>> >>
>> >> >>>> DOWN
>> >> >>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>> >> >>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>> >> >>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>> >> >>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>> >> >>>> Link policy: RSWITCH SNIFF
>> >> >>>> Link mode: SLAVE ACCEPT
>> >> >>>>
>> >> >>>> But If I unplug and plug USB dongle, and then try same command
>> >> >>>> (hciconfig
>> >> >>>> hci0 up), It works. Even "hcitool scan" command also working
>> after
>> >> >>>> that.
>> >> >>>>
>> >> >>>> Why 1st time not working when USB dongle is connected?
>> >> >>>> Also when I check Bluez debug log in logcat.
>> >> >>>> I am getting one error log when USB dongle connected during
>> boot.
>> >> >>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
>> >> >>>> (0x12).
>> >> >>>
>> >> >>> I think that blocked through rfkill is pretty obvious. Check with
>> >>
>> >> the
>> >>
>> >> >>> rfkill tool on what the current settings are. For some reason it
>> >>
>> >> seems
>> >>
>> >> >>> Bluetooth is blocked by default. And I remember there were some
>> >>
>> >> kernel
>> >>
>> >> >>> patches for this. Just do not remember the details.
>> >> >>>
>> >> >>> Regards
>> >> >>>
>> >> >>> Marcel
>> >> >>>
>> >> >>> --
>> >> >>> To unsubscribe from this list: send the line "unsubscribe
>> >> >>> linux-bluetooth"
>> >> >>> in
>> >> >>> the body of a message to [email protected]
>> >> >>> More majordomo info at
>> http://vger.kernel.org/majordomo-info.html
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> Thanks for the reply.
>> >> >>
>> >> >> In my busybox utils rfkill is not enabled. If I enable it and try
>> >> >> "rfkill
>> >> >> unblock" is that will be enough? or I need to search for Kernel
>> patch
>> >> >> that
>> >> >> fixes this rfkill block issue?
>> >> >
>> >> > Hi,
>> >> >
>> >> > By Analysing I found 3 scenarios and only in one scenario BT is
>> >>
>> >> working.
>> >>
>> >> > Scenario 1 : Connect USB BT Dongle and then boot the android
>> >>
>> >> device.Then
>> >>
>> >> > Turn on from Android Bluetooth settings
>> >> >
>> >> > Result: Not working. Rfkill block error.
>> >> > E/bluetoothd( 868): Failed to set mode: Blocked through rfkill
>> (0x12)
>> >> >
>> >> > Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug
>> >>
>> >> again.
>> >>
>> >> > Then Turn on from Android Bluetooth settings.
>> >> >
>> >> > Result: Working: BT turning on and scanning BT/BLE devices.
>> >> >
>> >> > Scenario 3: Boot Android device and then plug the USB BT
>> Dongle.Then
>> >>
>> >> Turn
>> >>
>> >> > on from Android Bluetooth settings.
>> >> >
>> >> > Result: Not working. Here we are not getting any debug prints from
>> >>
>> >> bluez.
>> >>
>> >> > Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
>> >> > connected during boot.
>> >> > From Logcat,observing following error messages
>> >> >
>> >> > IBluetooth.configHciSnoopLog return false
>> >> > Bluetooth module is not loaded
>> >> >
>> >> > Logcat:
>> >> >
>> >> > -------------------Start-------------------
>> >> > D/BluetoothManagerService( 543): enable(): mBluetooth =null
>> mBinding
>> >>
>> >> =
>> >>
>> >> > false
>> >> > D/BluetoothManagerService( 543): Message: 1
>> >> > D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
>> >> > D/BluetoothAdapterService( 1032): REFCOUNT: CREATED.
>> INSTANCE_COUNT2
>> >> > D/BluetoothAdapterState( 1032): make
>> >> > I/BluetoothAdapterState( 1032): Entering OffState
>> >> > D/BluetoothManagerService( 543): BluetoothServiceConnection:
>> >> > com.android.bluetooth.btservice.AdapterService
>> >> > D/BluetoothManagerService( 543): Message: 40
>> >>
>> >> > D/BluetoothManagerService( 543):
>> MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
>> >> 1
>> >>
>> >> > E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog
>> return
>> >> > false
>> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceUp
>> >>
>> >> callbacks
>> >>
>> >> > D/BluetoothManagerService( 543): Broadcasting
>> onBluetoothServiceUp()
>> >>
>> >> to 5
>> >>
>> >> > receivers.
>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>> >>
>> >> USER_TURN_ON
>> >>
>> >> > D/BluetoothAdapterProperties( 1032): Setting state to 11
>> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed:
>> 10->
>> >>
>> >> 11
>> >>
>> >> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState()
>> to
>> >>
>> >> 1
>> >>
>> >> > receivers.
>> >> > D/BluetoothManagerService( 543): Message: 60
>> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>> >> > prevState = 10, newState=11
>> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10
>> ->
>> >>
>> >> 11
>> >>
>> >> > D/BluetoothBondStateMachine( 1032): make
>> >> > D/BluetoothMapService( 1032): onReceive
>> >> > I/BluetoothBondStateMachine( 1032): StableState(): Entering Off
>> State
>> >> > D/HeadsetService( 1032): Received start request. Starting
>> profile...
>> >> > D/HeadsetStateMachine( 1032): make
>> >> > E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
>> >> > D/A2dpService( 1032): Received start request. Starting profile...
>> >> > V/Avrcp ( 1032): make
>> >> > E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
>> >> > D/A2dpStateMachine( 1032): make
>> >> > E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
>> >> > D/A2dpStateMachine( 1032): Enter Disconnected: -2
>> >> > D/HidService( 1032): Received start request. Starting profile...
>> >> > E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
>> >> > D/HealthService( 1032): Received start request. Starting profile...
>> >> > I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
>> >> > isTurningOn()=true, isTurningOff()=false
>> >> > E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.hdp.HealthService
>> >> > D/PanService( 1032): Received start request. Starting profile...
>> >> > D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
>> >> > E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
>> >> > Bluetooth module is not loaded##
>> >> > D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
>> >> > E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
>> >> > D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
>> >> > D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0
>> >>
>> >> mSignal=0
>> >>
>> >> > mRoam=0 mBatteryCharge=5
>> >> > D/BtGatt.GattService( 1032): Received start request. Starting
>> >>
>> >> profile...
>> >>
>> >> > D/BtGatt.GattService( 1032): start()
>> >> > E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
>> >> > jobject)(L694): Bluetooth module is not loaded##
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.hdp.HealthService
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.hdp.HealthService
>> >> > D/BluetoothMapService( 1032): Received start request. Starting
>> >>
>> >> profile...
>> >>
>> >> > D/BluetoothMapService( 1032): start()
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.map.BluetoothMapService
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.map.BluetoothMapService
>> >> > D/BluetoothAdapterService( 1032): Profile still not
>> >> > running:com.android.bluetooth.map.BluetoothMapService
>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE =
>> >>
>> >> STARTED,
>> >>
>> >> > isTurningOn=true, isTurningOff=false
>> >> > E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
>> >> > D/BluetoothAdapterProperties( 1032): Setting state to 10
>> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed:
>> 11->
>> >>
>> >> 10
>> >>
>> >> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState()
>> to
>> >>
>> >> 1
>> >>
>> >> > receivers.
>> >> > I/BluetoothAdapterState( 1032): Entering OffState
>> >> > D/BluetoothManagerService( 543): Message: 60
>> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>> >> > prevState = 11, newState=10
>> >> > D/BluetoothManagerService( 543): Broadcasting
>> >> > onBluetoothStateChange(false) to 10 receivers.
>> >> > D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
>> >> > D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
>> >> > D/BluetoothPbap( 851): onBluetoothStateChange: up=false
>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> >> > D/BluetoothMap( 851): onBluetoothStateChange: up=false
>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> >> > D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
>> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11
>> ->
>> >>
>> >> 10
>> >>
>> >> > E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
>> >> > D/BluetoothMapService( 1032): onReceive
>> >> > D/DockEventReceiver( 851): finishStartingService: stopping service
>> >> > W/ContextImpl( 851): Calling a method in the system process
>> without a
>> >> > qualified user: android.app.ContextImpl.startService:1487
>> >> > android.content.ContextWrapper.startService:494
>> >> > android.content.ContextWrapper.startService:494
>> >> > com.android.settings.bluetooth.DockEventReceiver.beginStartingService:1
>> >> > 34
>> >> > com.android.settings.bluetooth.DockEventReceiver.onReceive:115
>> >> > D/BluetoothManagerService( 543): Sending off request.
>> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>> >>
>> >> USER_TURN_OFF
>> >>
>> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceDown
>> >>
>> >> callbacks
>> >>
>> >> > D/BluetoothManagerService( 543): Broadcasting
>> >>
>> >> onBluetoothServiceDown() to
>> >>
>> >> > 5 receivers.
>> >> > D/BluetoothAdapterService( 1032): Cleaning up adapter native....
>> >> > D/BluetoothAdapterService( 1032): Done cleaning up adapter
>> native....
>> >> > D/BluetoothAdapterService(746876560)( 1032):
>> ****onDestroy()********
>> >> >
>> >> > -------------------End---------------------
>> >> >
>> >> > For Scenario 1 , I am trying to build rfkill tool for
>> >>
>> >> android(Currently no
>> >>
>> >> > success). Can we change the state from code by opening rfkill path
>> >> > "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
>> >> >
>> >> > But scenario 3 looks like I missed some configuration.
>> >> >
>> >> > What could be the problem?
>> >> >
>> >> > Regards,
>> >> > KP
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > To unsubscribe from this list: send the line "unsubscribe
>> >>
>> >> linux-bluetooth"
>> >>
>> >> > in
>> >> > the body of a message to [email protected]
>> >> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>> >>
>> >> Hi All,
>> >>
>> >>
>> >> I analysed the Android flow and found that Android System server will
>> >> initialize and check for bluetooth hardware on during Boot. So if we
>> >> connect the USB BT Dongle after boot Android BT service may not
>> identify
>> >> it.
>> >> May be this is the reason because of which scenario 3 (Boot Android
>> >> device
>> >> and then plug the USB BT Dongle.Then Turn on from Bluetooth setting)
>> is
>> >> not working.
>> >> This is my understanding. Correct me If I am wrong.
>> >>
>> >> Anyone tried USB BT pnp on android?
>> >
>> > This should work but you need to load modules on boot (or have all
>> > compiled
>> > into kernel).
>> >
>> > --
>> > BR
>> > Szymon Janc
>>
>> Hi Szymon,
>>
>> Bluez module is loading on boot. Some initial Bluez debug prints are
>> coming. like following logs which are coming initially
>>
>> -------------------------Log start---------
>> D/BlueZ ( 183):
>> external/bluetooth/bluez/android/hal-audio.c:audio_open()
>> D/BlueZ ( 183):
>> external/bluetooth/bluez/android/hal-audio.c:audio_ipc_init()
>> D/BlueZ ( 183):
>> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() D/BlueZ (
>> 183):
>> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() Waiting for
>> connection ...
>> E/BlueZ ( 183): APTX: failed to open library libbt-aptx.so (dlopen
>> failed: library "libbt-aptx.so" not found)
>> D/BlueZ ( 183):
>> external/bluetooth/bluez/android/hal-audio.c:audio_init_check()
>> D/BlueZ ( 183):
>> external/bluetooth/bluez/android/hal-audio.c:audio_set_master_volume()
>> --------------------------Log end---------------
>> But after that bluez function calls like
>> open_bluetooth,get_bluetooth_interface,init are getting called after
>> boot_completed signal received android, Its calling BluetoothMapService
>> and from there call is going to bluez over JNI.
>>
>> Below Log suggests that.
>> ------------------------Logcat start------------------------
>>
>> D/BluetoothManagerService( 531): Retrieving Bluetooth Adapter name and
>> address...
>> D/BluetoothManagerService( 531): getNameAndAddress(): mBluetooth = null
>> mBinding = false
>> D/BluetoothManagerService( 531): Message: 200
>> D/BluetoothManagerService( 531): MESSAGE_GET_NAME_AND_ADDRESS
>> D/BluetoothManagerService( 531): Binding to service to get name and
>> address
>> I/ActivityManager( 531): Start proc com.android.bluetooth for service
>> com.android.bluetooth/.btservice.AdapterService: pid=1037 uid=1002
>> gids={41002, 3003, 3002, 3001, 1028, 1015, 3005, 1016, 3008}
>> D/BluetoothManagerService( 531): Message: 30
>> D/BluetoothManagerService( 531): Message: 30
>> W/ContextImpl( 531): Calling a method in the system process without a
>> qualified user: android.app.ContextImpl.bindService:1551
>> android.bluetooth.BluetoothHeadset.doBind:283
>> android.bluetooth.BluetoothHeadset.<init>:276
>> android.bluetooth.BluetoothAdapter.getProfileProxy:1361
>> android.media.AudioService.getBluetoothHeadset:2255
>> W/ContextImpl( 531): Calling a method in the system process without a
>> qualified user: android.app.ContextImpl.bindService:1551
>> android.bluetooth.BluetoothA2dp.doBind:165
>> android.bluetooth.BluetoothA2dp.<init>:158
>> android.bluetooth.BluetoothAdapter.getProfileProxy:1364
>> android.media.AudioService$AudioServiceBroadcastReceiver.onReceive:4176
>> V/WiredAccessoryManager( 531): init()
>> W/WiredAccessoryManager( 531): /sys/class/switch/usb_audio/state not
>> found while attempting to determine initial switch state
>> I/PowerManagerService( 531): Boot animation finished.
>> I/Choreographer( 915): Skipped 148 frames! The application may be
>> doing
>> too much work on its main thread.
>> I/dalvikvm( 1037): DexOpt: mismatch dep signature for
>> '/system/framework/framework.odex'
>> E/dalvikvm( 1037): /system/framework/javax.obex.jar odex has stale
>> dependencies
>> I/dalvikvm( 1037): DexOpt: mismatch dep name:
>> '/data/dalvik-cache/system@[email protected]@classes.dex'
>> vs.
>> '/system/framework/telephony-common.odex'
>> E/dalvikvm( 1037): /system/app/Bluetooth.apk odex has stale dependencies
>> D/dalvikvm( 915): GC_CONCURRENT freed 1690K, 24% free 5645K/7408K,
>> paused
>> 3ms+2ms, total 25ms
>> D/AdapterServiceConfig( 1037): Adding HeadsetService
>> D/AdapterServiceConfig( 1037): Adding A2dpService
>> D/AdapterServiceConfig( 1037): Adding HidService
>> D/AdapterServiceConfig( 1037): Adding HealthService
>> D/AdapterServiceConfig( 1037): Adding PanService
>> D/AdapterServiceConfig( 1037): Adding GattService
>> D/AdapterServiceConfig( 1037): Adding BluetoothMapService
>> D/BlueZ ( 1037):
>> external/bluetooth/bluez/android/hal-bluetooth.c:open_bluetooth()
>> D/BlueZ ( 1037):
>> external/bluetooth/bluez/android/hal-bluetooth.c:get_bluetooth_interface()
>> D/BluetoothAdapterService( 1037): REFCOUNT: CREATED. INSTANCE_COUNT1
>> D/BluetoothManagerService( 531): Message: 20
>> D/BluetoothManagerService( 531): Added callback:
>> android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@2ca2f3a8:true
>> D/BluetoothAdapterState( 1037): make
>> D/BlueZ ( 1037):
>> external/bluetooth/bluez/android/hal-bluetooth.c:init()
>>
>> -------------------------End-----------------------------
>>
>> Android System server during init will get BT name and address and after
>> that I did not find any other place where it checks for name/address.
>> Correct me If I am wrong. or I am missing anything?
>>
>> hciconfig/hcitool is working fine if we connect BT dongle after
>> boot.Only
>> problem when we try to turn on BT from Android Bluetooth settings menu.
>>
>> Regards,
>> KP
>
> I don't think Android supports BT adapter hot-plug. What I mean by that is
> during Framework tries to initialize BT subsystem (and clean it up right
> after
> that). If that fails (eg due to no adapter being present) it will not try
> to
> initialize BT HAL again. So enabling BT from UI fails before even calling
> BT
> HAL.
>
> If adapter is present on boot, and then you remove it and plug it again it
> should work. Yet, if adapter is changed (so that address changes) you are
> entering uncharted territories, so you may see some subtle hiccups.
>
> --
> BR
> Szymon Janc
>

Hi Szymon,

Thanks for your reply.
I just checked BT enable flow from android and found that
When USB BT Dongle is not connected during bootm,During Bluez Init
(hal-bluetooth.c:init()), hal_ipc_accept is failing.
I hope IPC is failing as USB BT dongle is not connected.

>From below Logcat suggests that
E/BlueZ ( 799): bluetoothd connect timeout
E/BluetoothServiceJni( 799): Error while setting the callbacks
E/BluetoothAdapterState( 799): Error while turning Bluetooth On

because of this none of the BT interfaces are initialized.

When we connect the USB BT dongle , hal-bluetooth.c:init() is not getting
called. because of this BT enable is failing.


But in working case (USB BT dongle connected during boot). Each time when
we connect BT dongle, init is getting called.

I also observed that If I remove the USB dongle without turning off BT
from android BT settings menu, at that time
also init is not getting called and because of that BT will not get
enabled properly.

If we make "init" function to call whenever BT dongle it connected, is
that will be enough for BT HAL module to work
properly or any other settings might be required?

Regards,
KP

2015-09-09 07:36:06

by Szymon Janc

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

Hi,

On Tuesday 08 of September 2015 10:09:10 [email protected] wrote:
> > Hi,
> >
> > On Tuesday 08 of September 2015 09:04:18 [email protected] wrote:
> >> >>> Hi,
> >> >>>
> >> >>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB
> >>
> >> based
> >>
> >> >>>> Bluetooth device. I referred instruction in
> >> >>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README
> >>
> >> and
> >>
> >> >>>> able to build.
> >> >>>> After botting Android image with USB dongle connected and type
> >> >>>> "hciconfig
> >> >>>> hci0 up" on console, It is throwing following error.
> >> >>>> Can't init device hci0: Unknown error 132 (132)
> >> >>>>
> >> >>>> If I Type hciconfig -a . It gives following.
> >> >>>> hci0: Type: BR/EDR Bus: USB
> >> >>>>
> >> >>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU:
> >> 64:1
> >>
> >> >>>> DOWN
> >> >>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
> >> >>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
> >> >>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> >> >>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
> >> >>>> Link policy: RSWITCH SNIFF
> >> >>>> Link mode: SLAVE ACCEPT
> >> >>>>
> >> >>>> But If I unplug and plug USB dongle, and then try same command
> >> >>>> (hciconfig
> >> >>>> hci0 up), It works. Even "hcitool scan" command also working after
> >> >>>> that.
> >> >>>>
> >> >>>> Why 1st time not working when USB dongle is connected?
> >> >>>> Also when I check Bluez debug log in logcat.
> >> >>>> I am getting one error log when USB dongle connected during boot.
> >> >>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
> >> >>>> (0x12).
> >> >>>
> >> >>> I think that blocked through rfkill is pretty obvious. Check with
> >>
> >> the
> >>
> >> >>> rfkill tool on what the current settings are. For some reason it
> >>
> >> seems
> >>
> >> >>> Bluetooth is blocked by default. And I remember there were some
> >>
> >> kernel
> >>
> >> >>> patches for this. Just do not remember the details.
> >> >>>
> >> >>> Regards
> >> >>>
> >> >>> Marcel
> >> >>>
> >> >>> --
> >> >>> To unsubscribe from this list: send the line "unsubscribe
> >> >>> linux-bluetooth"
> >> >>> in
> >> >>> the body of a message to [email protected]
> >> >>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> >> >>
> >> >> Hi,
> >> >>
> >> >> Thanks for the reply.
> >> >>
> >> >> In my busybox utils rfkill is not enabled. If I enable it and try
> >> >> "rfkill
> >> >> unblock" is that will be enough? or I need to search for Kernel patch
> >> >> that
> >> >> fixes this rfkill block issue?
> >> >
> >> > Hi,
> >> >
> >> > By Analysing I found 3 scenarios and only in one scenario BT is
> >>
> >> working.
> >>
> >> > Scenario 1 : Connect USB BT Dongle and then boot the android
> >>
> >> device.Then
> >>
> >> > Turn on from Android Bluetooth settings
> >> >
> >> > Result: Not working. Rfkill block error.
> >> > E/bluetoothd( 868): Failed to set mode: Blocked through rfkill (0x12)
> >> >
> >> > Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug
> >>
> >> again.
> >>
> >> > Then Turn on from Android Bluetooth settings.
> >> >
> >> > Result: Working: BT turning on and scanning BT/BLE devices.
> >> >
> >> > Scenario 3: Boot Android device and then plug the USB BT Dongle.Then
> >>
> >> Turn
> >>
> >> > on from Android Bluetooth settings.
> >> >
> >> > Result: Not working. Here we are not getting any debug prints from
> >>
> >> bluez.
> >>
> >> > Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
> >> > connected during boot.
> >> > From Logcat,observing following error messages
> >> >
> >> > IBluetooth.configHciSnoopLog return false
> >> > Bluetooth module is not loaded
> >> >
> >> > Logcat:
> >> >
> >> > -------------------Start-------------------
> >> > D/BluetoothManagerService( 543): enable(): mBluetooth =null mBinding
> >>
> >> =
> >>
> >> > false
> >> > D/BluetoothManagerService( 543): Message: 1
> >> > D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
> >> > D/BluetoothAdapterService( 1032): REFCOUNT: CREATED. INSTANCE_COUNT2
> >> > D/BluetoothAdapterState( 1032): make
> >> > I/BluetoothAdapterState( 1032): Entering OffState
> >> > D/BluetoothManagerService( 543): BluetoothServiceConnection:
> >> > com.android.bluetooth.btservice.AdapterService
> >> > D/BluetoothManagerService( 543): Message: 40
> >>
> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
> >> 1
> >>
> >> > E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog return
> >> > false
> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceUp
> >>
> >> callbacks
> >>
> >> > D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceUp()
> >>
> >> to 5
> >>
> >> > receivers.
> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
> >>
> >> USER_TURN_ON
> >>
> >> > D/BluetoothAdapterProperties( 1032): Setting state to 11
> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 10->
> >>
> >> 11
> >>
> >> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to
> >>
> >> 1
> >>
> >> > receivers.
> >> > D/BluetoothManagerService( 543): Message: 60
> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> >> > prevState = 10, newState=11
> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10 ->
> >>
> >> 11
> >>
> >> > D/BluetoothBondStateMachine( 1032): make
> >> > D/BluetoothMapService( 1032): onReceive
> >> > I/BluetoothBondStateMachine( 1032): StableState(): Entering Off State
> >> > D/HeadsetService( 1032): Received start request. Starting profile...
> >> > D/HeadsetStateMachine( 1032): make
> >> > E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
> >> > D/A2dpService( 1032): Received start request. Starting profile...
> >> > V/Avrcp ( 1032): make
> >> > E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
> >> > D/A2dpStateMachine( 1032): make
> >> > E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
> >> > D/A2dpStateMachine( 1032): Enter Disconnected: -2
> >> > D/HidService( 1032): Received start request. Starting profile...
> >> > E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
> >> > D/HealthService( 1032): Received start request. Starting profile...
> >> > I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
> >> > isTurningOn()=true, isTurningOff()=false
> >> > E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.hdp.HealthService
> >> > D/PanService( 1032): Received start request. Starting profile...
> >> > D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
> >> > E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
> >> > Bluetooth module is not loaded##
> >> > D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
> >> > E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
> >> > D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
> >> > D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0
> >>
> >> mSignal=0
> >>
> >> > mRoam=0 mBatteryCharge=5
> >> > D/BtGatt.GattService( 1032): Received start request. Starting
> >>
> >> profile...
> >>
> >> > D/BtGatt.GattService( 1032): start()
> >> > E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
> >> > jobject)(L694): Bluetooth module is not loaded##
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.hdp.HealthService
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.hdp.HealthService
> >> > D/BluetoothMapService( 1032): Received start request. Starting
> >>
> >> profile...
> >>
> >> > D/BluetoothMapService( 1032): start()
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.map.BluetoothMapService
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.map.BluetoothMapService
> >> > D/BluetoothAdapterService( 1032): Profile still not
> >> > running:com.android.bluetooth.map.BluetoothMapService
> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE =
> >>
> >> STARTED,
> >>
> >> > isTurningOn=true, isTurningOff=false
> >> > E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
> >> > D/BluetoothAdapterProperties( 1032): Setting state to 10
> >> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 11->
> >>
> >> 10
> >>
> >> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to
> >>
> >> 1
> >>
> >> > receivers.
> >> > I/BluetoothAdapterState( 1032): Entering OffState
> >> > D/BluetoothManagerService( 543): Message: 60
> >> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> >> > prevState = 11, newState=10
> >> > D/BluetoothManagerService( 543): Broadcasting
> >> > onBluetoothStateChange(false) to 10 receivers.
> >> > D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
> >> > D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
> >> > D/BluetoothPbap( 851): onBluetoothStateChange: up=false
> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> >> > D/BluetoothMap( 851): onBluetoothStateChange: up=false
> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> >> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> >> > D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
> >> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11 ->
> >>
> >> 10
> >>
> >> > E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
> >> > D/BluetoothMapService( 1032): onReceive
> >> > D/DockEventReceiver( 851): finishStartingService: stopping service
> >> > W/ContextImpl( 851): Calling a method in the system process without a
> >> > qualified user: android.app.ContextImpl.startService:1487
> >> > android.content.ContextWrapper.startService:494
> >> > android.content.ContextWrapper.startService:494
> >> > com.android.settings.bluetooth.DockEventReceiver.beginStartingService:1
> >> > 34
> >> > com.android.settings.bluetooth.DockEventReceiver.onReceive:115
> >> > D/BluetoothManagerService( 543): Sending off request.
> >> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
> >>
> >> USER_TURN_OFF
> >>
> >> > D/BluetoothManagerService( 543): Calling onBluetoothServiceDown
> >>
> >> callbacks
> >>
> >> > D/BluetoothManagerService( 543): Broadcasting
> >>
> >> onBluetoothServiceDown() to
> >>
> >> > 5 receivers.
> >> > D/BluetoothAdapterService( 1032): Cleaning up adapter native....
> >> > D/BluetoothAdapterService( 1032): Done cleaning up adapter native....
> >> > D/BluetoothAdapterService(746876560)( 1032): ****onDestroy()********
> >> >
> >> > -------------------End---------------------
> >> >
> >> > For Scenario 1 , I am trying to build rfkill tool for
> >>
> >> android(Currently no
> >>
> >> > success). Can we change the state from code by opening rfkill path
> >> > "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
> >> >
> >> > But scenario 3 looks like I missed some configuration.
> >> >
> >> > What could be the problem?
> >> >
> >> > Regards,
> >> > KP
> >> >
> >> >
> >> >
> >> > --
> >> > To unsubscribe from this list: send the line "unsubscribe
> >>
> >> linux-bluetooth"
> >>
> >> > in
> >> > the body of a message to [email protected]
> >> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >>
> >> Hi All,
> >>
> >>
> >> I analysed the Android flow and found that Android System server will
> >> initialize and check for bluetooth hardware on during Boot. So if we
> >> connect the USB BT Dongle after boot Android BT service may not identify
> >> it.
> >> May be this is the reason because of which scenario 3 (Boot Android
> >> device
> >> and then plug the USB BT Dongle.Then Turn on from Bluetooth setting) is
> >> not working.
> >> This is my understanding. Correct me If I am wrong.
> >>
> >> Anyone tried USB BT pnp on android?
> >
> > This should work but you need to load modules on boot (or have all
> > compiled
> > into kernel).
> >
> > --
> > BR
> > Szymon Janc
>
> Hi Szymon,
>
> Bluez module is loading on boot. Some initial Bluez debug prints are
> coming. like following logs which are coming initially
>
> -------------------------Log start---------
> D/BlueZ ( 183): external/bluetooth/bluez/android/hal-audio.c:audio_open()
> D/BlueZ ( 183):
> external/bluetooth/bluez/android/hal-audio.c:audio_ipc_init()
> D/BlueZ ( 183):
> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() D/BlueZ (
> 183):
> external/bluetooth/bluez/android/hal-audio.c:ipc_handler() Waiting for
> connection ...
> E/BlueZ ( 183): APTX: failed to open library libbt-aptx.so (dlopen
> failed: library "libbt-aptx.so" not found)
> D/BlueZ ( 183):
> external/bluetooth/bluez/android/hal-audio.c:audio_init_check()
> D/BlueZ ( 183):
> external/bluetooth/bluez/android/hal-audio.c:audio_set_master_volume()
> --------------------------Log end---------------
> But after that bluez function calls like
> open_bluetooth,get_bluetooth_interface,init are getting called after
> boot_completed signal received android, Its calling BluetoothMapService
> and from there call is going to bluez over JNI.
>
> Below Log suggests that.
> ------------------------Logcat start------------------------
>
> D/BluetoothManagerService( 531): Retrieving Bluetooth Adapter name and
> address...
> D/BluetoothManagerService( 531): getNameAndAddress(): mBluetooth = null
> mBinding = false
> D/BluetoothManagerService( 531): Message: 200
> D/BluetoothManagerService( 531): MESSAGE_GET_NAME_AND_ADDRESS
> D/BluetoothManagerService( 531): Binding to service to get name and address
> I/ActivityManager( 531): Start proc com.android.bluetooth for service
> com.android.bluetooth/.btservice.AdapterService: pid=1037 uid=1002
> gids={41002, 3003, 3002, 3001, 1028, 1015, 3005, 1016, 3008}
> D/BluetoothManagerService( 531): Message: 30
> D/BluetoothManagerService( 531): Message: 30
> W/ContextImpl( 531): Calling a method in the system process without a
> qualified user: android.app.ContextImpl.bindService:1551
> android.bluetooth.BluetoothHeadset.doBind:283
> android.bluetooth.BluetoothHeadset.<init>:276
> android.bluetooth.BluetoothAdapter.getProfileProxy:1361
> android.media.AudioService.getBluetoothHeadset:2255
> W/ContextImpl( 531): Calling a method in the system process without a
> qualified user: android.app.ContextImpl.bindService:1551
> android.bluetooth.BluetoothA2dp.doBind:165
> android.bluetooth.BluetoothA2dp.<init>:158
> android.bluetooth.BluetoothAdapter.getProfileProxy:1364
> android.media.AudioService$AudioServiceBroadcastReceiver.onReceive:4176
> V/WiredAccessoryManager( 531): init()
> W/WiredAccessoryManager( 531): /sys/class/switch/usb_audio/state not
> found while attempting to determine initial switch state
> I/PowerManagerService( 531): Boot animation finished.
> I/Choreographer( 915): Skipped 148 frames! The application may be doing
> too much work on its main thread.
> I/dalvikvm( 1037): DexOpt: mismatch dep signature for
> '/system/framework/framework.odex'
> E/dalvikvm( 1037): /system/framework/javax.obex.jar odex has stale
> dependencies
> I/dalvikvm( 1037): DexOpt: mismatch dep name:
> '/data/dalvik-cache/system@[email protected]@classes.dex' vs.
> '/system/framework/telephony-common.odex'
> E/dalvikvm( 1037): /system/app/Bluetooth.apk odex has stale dependencies
> D/dalvikvm( 915): GC_CONCURRENT freed 1690K, 24% free 5645K/7408K, paused
> 3ms+2ms, total 25ms
> D/AdapterServiceConfig( 1037): Adding HeadsetService
> D/AdapterServiceConfig( 1037): Adding A2dpService
> D/AdapterServiceConfig( 1037): Adding HidService
> D/AdapterServiceConfig( 1037): Adding HealthService
> D/AdapterServiceConfig( 1037): Adding PanService
> D/AdapterServiceConfig( 1037): Adding GattService
> D/AdapterServiceConfig( 1037): Adding BluetoothMapService
> D/BlueZ ( 1037):
> external/bluetooth/bluez/android/hal-bluetooth.c:open_bluetooth()
> D/BlueZ ( 1037):
> external/bluetooth/bluez/android/hal-bluetooth.c:get_bluetooth_interface()
> D/BluetoothAdapterService( 1037): REFCOUNT: CREATED. INSTANCE_COUNT1
> D/BluetoothManagerService( 531): Message: 20
> D/BluetoothManagerService( 531): Added callback:
> android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@2ca2f3a8:true
> D/BluetoothAdapterState( 1037): make
> D/BlueZ ( 1037): external/bluetooth/bluez/android/hal-bluetooth.c:init()
>
> -------------------------End-----------------------------
>
> Android System server during init will get BT name and address and after
> that I did not find any other place where it checks for name/address.
> Correct me If I am wrong. or I am missing anything?
>
> hciconfig/hcitool is working fine if we connect BT dongle after boot.Only
> problem when we try to turn on BT from Android Bluetooth settings menu.
>
> Regards,
> KP

I don't think Android supports BT adapter hot-plug. What I mean by that is
during Framework tries to initialize BT subsystem (and clean it up right after
that). If that fails (eg due to no adapter being present) it will not try to
initialize BT HAL again. So enabling BT from UI fails before even calling BT
HAL.

If adapter is present on boot, and then you remove it and plug it again it
should work. Yet, if adapter is changed (so that address changes) you are
entering uncharted territories, so you may see some subtle hiccups.

--
BR
Szymon Janc

2015-09-08 14:09:10

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

> Hi,
>
> On Tuesday 08 of September 2015 09:04:18 [email protected] wrote:
>> >>> Hi,
>> >>>
>> >>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB
>> based
>> >>>> Bluetooth device. I referred instruction in
>> >>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README
>> and
>> >>>> able to build.
>> >>>> After botting Android image with USB dongle connected and type
>> >>>> "hciconfig
>> >>>> hci0 up" on console, It is throwing following error.
>> >>>> Can't init device hci0: Unknown error 132 (132)
>> >>>>
>> >>>> If I Type hciconfig -a . It gives following.
>> >>>> hci0: Type: BR/EDR Bus: USB
>> >>>>
>> >>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU:
>> 64:1
>> >>>> DOWN
>> >>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>> >>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>> >>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>> >>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>> >>>> Link policy: RSWITCH SNIFF
>> >>>> Link mode: SLAVE ACCEPT
>> >>>>
>> >>>> But If I unplug and plug USB dongle, and then try same command
>> >>>> (hciconfig
>> >>>> hci0 up), It works. Even "hcitool scan" command also working after
>> >>>> that.
>> >>>>
>> >>>> Why 1st time not working when USB dongle is connected?
>> >>>> Also when I check Bluez debug log in logcat.
>> >>>> I am getting one error log when USB dongle connected during boot.
>> >>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
>> >>>> (0x12).
>> >>>
>> >>> I think that blocked through rfkill is pretty obvious. Check with
>> the
>> >>> rfkill tool on what the current settings are. For some reason it
>> seems
>> >>> Bluetooth is blocked by default. And I remember there were some
>> kernel
>> >>> patches for this. Just do not remember the details.
>> >>>
>> >>> Regards
>> >>>
>> >>> Marcel
>> >>>
>> >>> --
>> >>> To unsubscribe from this list: send the line "unsubscribe
>> >>> linux-bluetooth"
>> >>> in
>> >>> the body of a message to [email protected]
>> >>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> >>
>> >> Hi,
>> >>
>> >> Thanks for the reply.
>> >>
>> >> In my busybox utils rfkill is not enabled. If I enable it and try
>> >> "rfkill
>> >> unblock" is that will be enough? or I need to search for Kernel patch
>> >> that
>> >> fixes this rfkill block issue?
>> >
>> > Hi,
>> >
>> > By Analysing I found 3 scenarios and only in one scenario BT is
>> working.
>> > Scenario 1 : Connect USB BT Dongle and then boot the android
>> device.Then
>> > Turn on from Android Bluetooth settings
>> >
>> > Result: Not working. Rfkill block error.
>> > E/bluetoothd( 868): Failed to set mode: Blocked through rfkill (0x12)
>> >
>> > Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug
>> again.
>> > Then Turn on from Android Bluetooth settings.
>> >
>> > Result: Working: BT turning on and scanning BT/BLE devices.
>> >
>> > Scenario 3: Boot Android device and then plug the USB BT Dongle.Then
>> Turn
>> > on from Android Bluetooth settings.
>> >
>> > Result: Not working. Here we are not getting any debug prints from
>> bluez.
>> > Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
>> > connected during boot.
>> > From Logcat,observing following error messages
>> >
>> > IBluetooth.configHciSnoopLog return false
>> > Bluetooth module is not loaded
>> >
>> > Logcat:
>> >
>> > -------------------Start-------------------
>> > D/BluetoothManagerService( 543): enable(): mBluetooth =null mBinding
>> =
>> > false
>> > D/BluetoothManagerService( 543): Message: 1
>> > D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
>> > D/BluetoothAdapterService( 1032): REFCOUNT: CREATED. INSTANCE_COUNT2
>> > D/BluetoothAdapterState( 1032): make
>> > I/BluetoothAdapterState( 1032): Entering OffState
>> > D/BluetoothManagerService( 543): BluetoothServiceConnection:
>> > com.android.bluetooth.btservice.AdapterService
>> > D/BluetoothManagerService( 543): Message: 40
>> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
>> 1
>> > E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog return
>> > false
>> > D/BluetoothManagerService( 543): Calling onBluetoothServiceUp
>> callbacks
>> > D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceUp()
>> to 5
>> > receivers.
>> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>> USER_TURN_ON
>> > D/BluetoothAdapterProperties( 1032): Setting state to 11
>> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 10->
>> 11
>> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to
>> 1
>> > receivers.
>> > D/BluetoothManagerService( 543): Message: 60
>> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>> > prevState = 10, newState=11
>> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10 ->
>> 11
>> > D/BluetoothBondStateMachine( 1032): make
>> > D/BluetoothMapService( 1032): onReceive
>> > I/BluetoothBondStateMachine( 1032): StableState(): Entering Off State
>> > D/HeadsetService( 1032): Received start request. Starting profile...
>> > D/HeadsetStateMachine( 1032): make
>> > E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
>> > D/A2dpService( 1032): Received start request. Starting profile...
>> > V/Avrcp ( 1032): make
>> > E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
>> > D/A2dpStateMachine( 1032): make
>> > E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
>> > D/A2dpStateMachine( 1032): Enter Disconnected: -2
>> > D/HidService( 1032): Received start request. Starting profile...
>> > E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
>> > D/HealthService( 1032): Received start request. Starting profile...
>> > I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
>> > isTurningOn()=true, isTurningOff()=false
>> > E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.hdp.HealthService
>> > D/PanService( 1032): Received start request. Starting profile...
>> > D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
>> > E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
>> > Bluetooth module is not loaded##
>> > D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
>> > E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
>> > D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
>> > D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0
>> mSignal=0
>> > mRoam=0 mBatteryCharge=5
>> > D/BtGatt.GattService( 1032): Received start request. Starting
>> profile...
>> > D/BtGatt.GattService( 1032): start()
>> > E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
>> > jobject)(L694): Bluetooth module is not loaded##
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.hdp.HealthService
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.hdp.HealthService
>> > D/BluetoothMapService( 1032): Received start request. Starting
>> profile...
>> > D/BluetoothMapService( 1032): start()
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.map.BluetoothMapService
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.map.BluetoothMapService
>> > D/BluetoothAdapterService( 1032): Profile still not
>> > running:com.android.bluetooth.map.BluetoothMapService
>> > D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE =
>> STARTED,
>> > isTurningOn=true, isTurningOff=false
>> > E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
>> > D/BluetoothAdapterProperties( 1032): Setting state to 10
>> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 11->
>> 10
>> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to
>> 1
>> > receivers.
>> > I/BluetoothAdapterState( 1032): Entering OffState
>> > D/BluetoothManagerService( 543): Message: 60
>> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
>> > prevState = 11, newState=10
>> > D/BluetoothManagerService( 543): Broadcasting
>> > onBluetoothStateChange(false) to 10 receivers.
>> > D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
>> > D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
>> > D/BluetoothPbap( 851): onBluetoothStateChange: up=false
>> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> > D/BluetoothMap( 851): onBluetoothStateChange: up=false
>> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
>> > D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
>> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11 ->
>> 10
>> > E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
>> > D/BluetoothMapService( 1032): onReceive
>> > D/DockEventReceiver( 851): finishStartingService: stopping service
>> > W/ContextImpl( 851): Calling a method in the system process without a
>> > qualified user: android.app.ContextImpl.startService:1487
>> > android.content.ContextWrapper.startService:494
>> > android.content.ContextWrapper.startService:494
>> > com.android.settings.bluetooth.DockEventReceiver.beginStartingService:134
>> > com.android.settings.bluetooth.DockEventReceiver.onReceive:115
>> > D/BluetoothManagerService( 543): Sending off request.
>> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE =
>> USER_TURN_OFF
>> > D/BluetoothManagerService( 543): Calling onBluetoothServiceDown
>> callbacks
>> > D/BluetoothManagerService( 543): Broadcasting
>> onBluetoothServiceDown() to
>> > 5 receivers.
>> > D/BluetoothAdapterService( 1032): Cleaning up adapter native....
>> > D/BluetoothAdapterService( 1032): Done cleaning up adapter native....
>> > D/BluetoothAdapterService(746876560)( 1032): ****onDestroy()********
>> >
>> > -------------------End---------------------
>> >
>> > For Scenario 1 , I am trying to build rfkill tool for
>> android(Currently no
>> > success). Can we change the state from code by opening rfkill path
>> > "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
>> >
>> > But scenario 3 looks like I missed some configuration.
>> >
>> > What could be the problem?
>> >
>> > Regards,
>> > KP
>> >
>> >
>> >
>> > --
>> > To unsubscribe from this list: send the line "unsubscribe
>> linux-bluetooth"
>> > in
>> > the body of a message to [email protected]
>> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>> Hi All,
>>
>>
>> I analysed the Android flow and found that Android System server will
>> initialize and check for bluetooth hardware on during Boot. So if we
>> connect the USB BT Dongle after boot Android BT service may not identify
>> it.
>> May be this is the reason because of which scenario 3 (Boot Android
>> device
>> and then plug the USB BT Dongle.Then Turn on from Bluetooth setting) is
>> not working.
>> This is my understanding. Correct me If I am wrong.
>>
>> Anyone tried USB BT pnp on android?
>
> This should work but you need to load modules on boot (or have all
> compiled
> into kernel).
>
> --
> BR
> Szymon Janc
>

Hi Szymon,

Bluez module is loading on boot. Some initial Bluez debug prints are
coming. like following logs which are coming initially

-------------------------Log start---------
D/BlueZ ( 183): external/bluetooth/bluez/android/hal-audio.c:audio_open()
D/BlueZ ( 183):
external/bluetooth/bluez/android/hal-audio.c:audio_ipc_init()
D/BlueZ ( 183): external/bluetooth/bluez/android/hal-audio.c:ipc_handler()
D/BlueZ ( 183):
external/bluetooth/bluez/android/hal-audio.c:ipc_handler() Waiting for
connection ...
E/BlueZ ( 183): APTX: failed to open library libbt-aptx.so (dlopen
failed: library "libbt-aptx.so" not found)
D/BlueZ ( 183):
external/bluetooth/bluez/android/hal-audio.c:audio_init_check()
D/BlueZ ( 183):
external/bluetooth/bluez/android/hal-audio.c:audio_set_master_volume()
--------------------------Log end---------------
But after that bluez function calls like
open_bluetooth,get_bluetooth_interface,init are getting called after
boot_completed signal received android, Its calling BluetoothMapService
and from there call is going to bluez over JNI.

Below Log suggests that.
------------------------Logcat start------------------------

D/BluetoothManagerService( 531): Retrieving Bluetooth Adapter name and
address...
D/BluetoothManagerService( 531): getNameAndAddress(): mBluetooth = null
mBinding = false
D/BluetoothManagerService( 531): Message: 200
D/BluetoothManagerService( 531): MESSAGE_GET_NAME_AND_ADDRESS
D/BluetoothManagerService( 531): Binding to service to get name and address
I/ActivityManager( 531): Start proc com.android.bluetooth for service
com.android.bluetooth/.btservice.AdapterService: pid=1037 uid=1002
gids={41002, 3003, 3002, 3001, 1028, 1015, 3005, 1016, 3008}
D/BluetoothManagerService( 531): Message: 30
D/BluetoothManagerService( 531): Message: 30
W/ContextImpl( 531): Calling a method in the system process without a
qualified user: android.app.ContextImpl.bindService:1551
android.bluetooth.BluetoothHeadset.doBind:283
android.bluetooth.BluetoothHeadset.<init>:276
android.bluetooth.BluetoothAdapter.getProfileProxy:1361
android.media.AudioService.getBluetoothHeadset:2255
W/ContextImpl( 531): Calling a method in the system process without a
qualified user: android.app.ContextImpl.bindService:1551
android.bluetooth.BluetoothA2dp.doBind:165
android.bluetooth.BluetoothA2dp.<init>:158
android.bluetooth.BluetoothAdapter.getProfileProxy:1364
android.media.AudioService$AudioServiceBroadcastReceiver.onReceive:4176
V/WiredAccessoryManager( 531): init()
W/WiredAccessoryManager( 531): /sys/class/switch/usb_audio/state not
found while attempting to determine initial switch state
I/PowerManagerService( 531): Boot animation finished.
I/Choreographer( 915): Skipped 148 frames! The application may be doing
too much work on its main thread.
I/dalvikvm( 1037): DexOpt: mismatch dep signature for
'/system/framework/framework.odex'
E/dalvikvm( 1037): /system/framework/javax.obex.jar odex has stale
dependencies
I/dalvikvm( 1037): DexOpt: mismatch dep name:
'/data/dalvik-cache/system@[email protected]@classes.dex' vs.
'/system/framework/telephony-common.odex'
E/dalvikvm( 1037): /system/app/Bluetooth.apk odex has stale dependencies
D/dalvikvm( 915): GC_CONCURRENT freed 1690K, 24% free 5645K/7408K, paused
3ms+2ms, total 25ms
D/AdapterServiceConfig( 1037): Adding HeadsetService
D/AdapterServiceConfig( 1037): Adding A2dpService
D/AdapterServiceConfig( 1037): Adding HidService
D/AdapterServiceConfig( 1037): Adding HealthService
D/AdapterServiceConfig( 1037): Adding PanService
D/AdapterServiceConfig( 1037): Adding GattService
D/AdapterServiceConfig( 1037): Adding BluetoothMapService
D/BlueZ ( 1037):
external/bluetooth/bluez/android/hal-bluetooth.c:open_bluetooth()
D/BlueZ ( 1037):
external/bluetooth/bluez/android/hal-bluetooth.c:get_bluetooth_interface()
D/BluetoothAdapterService( 1037): REFCOUNT: CREATED. INSTANCE_COUNT1
D/BluetoothManagerService( 531): Message: 20
D/BluetoothManagerService( 531): Added callback:
android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@2ca2f3a8:true
D/BluetoothAdapterState( 1037): make
D/BlueZ ( 1037): external/bluetooth/bluez/android/hal-bluetooth.c:init()

-------------------------End-----------------------------

Android System server during init will get BT name and address and after
that I did not find any other place where it checks for name/address.
Correct me If I am wrong. or I am missing anything?

hciconfig/hcitool is working fine if we connect BT dongle after boot.Only
problem when we try to turn on BT from Android Bluetooth settings menu.

Regards,
KP

2015-09-08 13:12:29

by Szymon Janc

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

Hi,

On Tuesday 08 of September 2015 09:04:18 [email protected] wrote:
> >>> Hi,
> >>>
> >>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
> >>>> Bluetooth device. I referred instruction in
> >>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
> >>>> able to build.
> >>>> After botting Android image with USB dongle connected and type
> >>>> "hciconfig
> >>>> hci0 up" on console, It is throwing following error.
> >>>> Can't init device hci0: Unknown error 132 (132)
> >>>>
> >>>> If I Type hciconfig -a . It gives following.
> >>>> hci0: Type: BR/EDR Bus: USB
> >>>>
> >>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
> >>>> DOWN
> >>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
> >>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
> >>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> >>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
> >>>> Link policy: RSWITCH SNIFF
> >>>> Link mode: SLAVE ACCEPT
> >>>>
> >>>> But If I unplug and plug USB dongle, and then try same command
> >>>> (hciconfig
> >>>> hci0 up), It works. Even "hcitool scan" command also working after
> >>>> that.
> >>>>
> >>>> Why 1st time not working when USB dongle is connected?
> >>>> Also when I check Bluez debug log in logcat.
> >>>> I am getting one error log when USB dongle connected during boot.
> >>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
> >>>> (0x12).
> >>>
> >>> I think that blocked through rfkill is pretty obvious. Check with the
> >>> rfkill tool on what the current settings are. For some reason it seems
> >>> Bluetooth is blocked by default. And I remember there were some kernel
> >>> patches for this. Just do not remember the details.
> >>>
> >>> Regards
> >>>
> >>> Marcel
> >>>
> >>> --
> >>> To unsubscribe from this list: send the line "unsubscribe
> >>> linux-bluetooth"
> >>> in
> >>> the body of a message to [email protected]
> >>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> >>
> >> Hi,
> >>
> >> Thanks for the reply.
> >>
> >> In my busybox utils rfkill is not enabled. If I enable it and try
> >> "rfkill
> >> unblock" is that will be enough? or I need to search for Kernel patch
> >> that
> >> fixes this rfkill block issue?
> >
> > Hi,
> >
> > By Analysing I found 3 scenarios and only in one scenario BT is working.
> > Scenario 1 : Connect USB BT Dongle and then boot the android device.Then
> > Turn on from Android Bluetooth settings
> >
> > Result: Not working. Rfkill block error.
> > E/bluetoothd( 868): Failed to set mode: Blocked through rfkill (0x12)
> >
> > Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug again.
> > Then Turn on from Android Bluetooth settings.
> >
> > Result: Working: BT turning on and scanning BT/BLE devices.
> >
> > Scenario 3: Boot Android device and then plug the USB BT Dongle.Then Turn
> > on from Android Bluetooth settings.
> >
> > Result: Not working. Here we are not getting any debug prints from bluez.
> > Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
> > connected during boot.
> > From Logcat,observing following error messages
> >
> > IBluetooth.configHciSnoopLog return false
> > Bluetooth module is not loaded
> >
> > Logcat:
> >
> > -------------------Start-------------------
> > D/BluetoothManagerService( 543): enable(): mBluetooth =null mBinding =
> > false
> > D/BluetoothManagerService( 543): Message: 1
> > D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
> > D/BluetoothAdapterService( 1032): REFCOUNT: CREATED. INSTANCE_COUNT2
> > D/BluetoothAdapterState( 1032): make
> > I/BluetoothAdapterState( 1032): Entering OffState
> > D/BluetoothManagerService( 543): BluetoothServiceConnection:
> > com.android.bluetooth.btservice.AdapterService
> > D/BluetoothManagerService( 543): Message: 40
> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 1
> > E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog return
> > false
> > D/BluetoothManagerService( 543): Calling onBluetoothServiceUp callbacks
> > D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceUp() to 5
> > receivers.
> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_ON
> > D/BluetoothAdapterProperties( 1032): Setting state to 11
> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 10-> 11
> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
> > receivers.
> > D/BluetoothManagerService( 543): Message: 60
> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> > prevState = 10, newState=11
> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10 -> 11
> > D/BluetoothBondStateMachine( 1032): make
> > D/BluetoothMapService( 1032): onReceive
> > I/BluetoothBondStateMachine( 1032): StableState(): Entering Off State
> > D/HeadsetService( 1032): Received start request. Starting profile...
> > D/HeadsetStateMachine( 1032): make
> > E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
> > D/A2dpService( 1032): Received start request. Starting profile...
> > V/Avrcp ( 1032): make
> > E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
> > D/A2dpStateMachine( 1032): make
> > E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
> > D/A2dpStateMachine( 1032): Enter Disconnected: -2
> > D/HidService( 1032): Received start request. Starting profile...
> > E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
> > D/HealthService( 1032): Received start request. Starting profile...
> > I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
> > isTurningOn()=true, isTurningOff()=false
> > E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.hdp.HealthService
> > D/PanService( 1032): Received start request. Starting profile...
> > D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
> > E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
> > Bluetooth module is not loaded##
> > D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
> > E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
> > D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
> > D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0 mSignal=0
> > mRoam=0 mBatteryCharge=5
> > D/BtGatt.GattService( 1032): Received start request. Starting profile...
> > D/BtGatt.GattService( 1032): start()
> > E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
> > jobject)(L694): Bluetooth module is not loaded##
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.hdp.HealthService
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.hdp.HealthService
> > D/BluetoothMapService( 1032): Received start request. Starting profile...
> > D/BluetoothMapService( 1032): start()
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.map.BluetoothMapService
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.map.BluetoothMapService
> > D/BluetoothAdapterService( 1032): Profile still not
> > running:com.android.bluetooth.map.BluetoothMapService
> > D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE = STARTED,
> > isTurningOn=true, isTurningOff=false
> > E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
> > D/BluetoothAdapterProperties( 1032): Setting state to 10
> > I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 11-> 10
> > D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
> > receivers.
> > I/BluetoothAdapterState( 1032): Entering OffState
> > D/BluetoothManagerService( 543): Message: 60
> > D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> > prevState = 11, newState=10
> > D/BluetoothManagerService( 543): Broadcasting
> > onBluetoothStateChange(false) to 10 receivers.
> > D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
> > D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
> > D/BluetoothPbap( 851): onBluetoothStateChange: up=false
> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> > D/BluetoothMap( 851): onBluetoothStateChange: up=false
> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> > D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> > D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
> > D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11 -> 10
> > E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
> > D/BluetoothMapService( 1032): onReceive
> > D/DockEventReceiver( 851): finishStartingService: stopping service
> > W/ContextImpl( 851): Calling a method in the system process without a
> > qualified user: android.app.ContextImpl.startService:1487
> > android.content.ContextWrapper.startService:494
> > android.content.ContextWrapper.startService:494
> > com.android.settings.bluetooth.DockEventReceiver.beginStartingService:134
> > com.android.settings.bluetooth.DockEventReceiver.onReceive:115
> > D/BluetoothManagerService( 543): Sending off request.
> > D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_OFF
> > D/BluetoothManagerService( 543): Calling onBluetoothServiceDown callbacks
> > D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceDown() to
> > 5 receivers.
> > D/BluetoothAdapterService( 1032): Cleaning up adapter native....
> > D/BluetoothAdapterService( 1032): Done cleaning up adapter native....
> > D/BluetoothAdapterService(746876560)( 1032): ****onDestroy()********
> >
> > -------------------End---------------------
> >
> > For Scenario 1 , I am trying to build rfkill tool for android(Currently no
> > success). Can we change the state from code by opening rfkill path
> > "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
> >
> > But scenario 3 looks like I missed some configuration.
> >
> > What could be the problem?
> >
> > Regards,
> > KP
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> > in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> Hi All,
>
>
> I analysed the Android flow and found that Android System server will
> initialize and check for bluetooth hardware on during Boot. So if we
> connect the USB BT Dongle after boot Android BT service may not identify
> it.
> May be this is the reason because of which scenario 3 (Boot Android device
> and then plug the USB BT Dongle.Then Turn on from Bluetooth setting) is
> not working.
> This is my understanding. Correct me If I am wrong.
>
> Anyone tried USB BT pnp on android?

This should work but you need to load modules on boot (or have all compiled
into kernel).

--
BR
Szymon Janc

2015-09-08 13:04:18

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

>>> Hi,
>>>
>>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
>>>> Bluetooth device. I referred instruction in
>>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
>>>> able to build.
>>>> After botting Android image with USB dongle connected and type
>>>> "hciconfig
>>>> hci0 up" on console, It is throwing following error.
>>>> Can't init device hci0: Unknown error 132 (132)
>>>>
>>>> If I Type hciconfig -a . It gives following.
>>>> hci0: Type: BR/EDR Bus: USB
>>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
>>>> DOWN
>>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>>>> Link policy: RSWITCH SNIFF
>>>> Link mode: SLAVE ACCEPT
>>>>
>>>>
>>>>
>>>> But If I unplug and plug USB dongle, and then try same command
>>>> (hciconfig
>>>> hci0 up), It works. Even "hcitool scan" command also working after
>>>> that.
>>>>
>>>> Why 1st time not working when USB dongle is connected?
>>>> Also when I check Bluez debug log in logcat.
>>>> I am getting one error log when USB dongle connected during boot.
>>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill
>>>> (0x12).
>>>
>>> I think that blocked through rfkill is pretty obvious. Check with the
>>> rfkill tool on what the current settings are. For some reason it seems
>>> Bluetooth is blocked by default. And I remember there were some kernel
>>> patches for this. Just do not remember the details.
>>>
>>> Regards
>>>
>>> Marcel
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe
>>> linux-bluetooth"
>>> in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>
>> Hi,
>>
>> Thanks for the reply.
>>
>> In my busybox utils rfkill is not enabled. If I enable it and try
>> "rfkill
>> unblock" is that will be enough? or I need to search for Kernel patch
>> that
>> fixes this rfkill block issue?
>
> Hi,
>
> By Analysing I found 3 scenarios and only in one scenario BT is working.
> Scenario 1 : Connect USB BT Dongle and then boot the android device.Then
> Turn on from Android Bluetooth settings
>
> Result: Not working. Rfkill block error.
> E/bluetoothd( 868): Failed to set mode: Blocked through rfkill (0x12)
>
> Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug again.
> Then Turn on from Android Bluetooth settings.
>
> Result: Working: BT turning on and scanning BT/BLE devices.
>
> Scenario 3: Boot Android device and then plug the USB BT Dongle.Then Turn
> on from Android Bluetooth settings.
>
> Result: Not working. Here we are not getting any debug prints from bluez.
> Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
> connected during boot.
> From Logcat,observing following error messages
> IBluetooth.configHciSnoopLog return false
> Bluetooth module is not loaded
>
> Logcat:
>
> -------------------Start-------------------
> D/BluetoothManagerService( 543): enable(): mBluetooth =null mBinding =
> false
> D/BluetoothManagerService( 543): Message: 1
> D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
> D/BluetoothAdapterService( 1032): REFCOUNT: CREATED. INSTANCE_COUNT2
> D/BluetoothAdapterState( 1032): make
> I/BluetoothAdapterState( 1032): Entering OffState
> D/BluetoothManagerService( 543): BluetoothServiceConnection:
> com.android.bluetooth.btservice.AdapterService
> D/BluetoothManagerService( 543): Message: 40
> D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 1
> E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog return
> false
> D/BluetoothManagerService( 543): Calling onBluetoothServiceUp callbacks
> D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceUp() to 5
> receivers.
> D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_ON
> D/BluetoothAdapterProperties( 1032): Setting state to 11
> I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 10-> 11
> D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
> receivers.
> D/BluetoothManagerService( 543): Message: 60
> D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> prevState = 10, newState=11
> D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10 -> 11
> D/BluetoothBondStateMachine( 1032): make
> D/BluetoothMapService( 1032): onReceive
> I/BluetoothBondStateMachine( 1032): StableState(): Entering Off State
> D/HeadsetService( 1032): Received start request. Starting profile...
> D/HeadsetStateMachine( 1032): make
> E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
> D/A2dpService( 1032): Received start request. Starting profile...
> V/Avrcp ( 1032): make
> E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
> D/A2dpStateMachine( 1032): make
> E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
> D/A2dpStateMachine( 1032): Enter Disconnected: -2
> D/HidService( 1032): Received start request. Starting profile...
> E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
> D/HealthService( 1032): Received start request. Starting profile...
> I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
> isTurningOn()=true, isTurningOff()=false
> E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.hdp.HealthService
> D/PanService( 1032): Received start request. Starting profile...
> D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
> E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
> Bluetooth module is not loaded##
> D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
> E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
> D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
> D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0 mSignal=0
> mRoam=0 mBatteryCharge=5
> D/BtGatt.GattService( 1032): Received start request. Starting profile...
> D/BtGatt.GattService( 1032): start()
> E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
> jobject)(L694): Bluetooth module is not loaded##
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.hdp.HealthService
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.hdp.HealthService
> D/BluetoothMapService( 1032): Received start request. Starting profile...
> D/BluetoothMapService( 1032): start()
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.map.BluetoothMapService
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.map.BluetoothMapService
> D/BluetoothAdapterService( 1032): Profile still not
> running:com.android.bluetooth.map.BluetoothMapService
> D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE = STARTED,
> isTurningOn=true, isTurningOff=false
> E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
> D/BluetoothAdapterProperties( 1032): Setting state to 10
> I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 11-> 10
> D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
> receivers.
> I/BluetoothAdapterState( 1032): Entering OffState
> D/BluetoothManagerService( 543): Message: 60
> D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
> prevState = 11, newState=10
> D/BluetoothManagerService( 543): Broadcasting
> onBluetoothStateChange(false) to 10 receivers.
> D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
> D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
> D/BluetoothPbap( 851): onBluetoothStateChange: up=false
> D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> D/BluetoothMap( 851): onBluetoothStateChange: up=false
> D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
> D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
> D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11 -> 10
> E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
> D/BluetoothMapService( 1032): onReceive
> D/DockEventReceiver( 851): finishStartingService: stopping service
> W/ContextImpl( 851): Calling a method in the system process without a
> qualified user: android.app.ContextImpl.startService:1487
> android.content.ContextWrapper.startService:494
> android.content.ContextWrapper.startService:494
> com.android.settings.bluetooth.DockEventReceiver.beginStartingService:134
> com.android.settings.bluetooth.DockEventReceiver.onReceive:115
> D/BluetoothManagerService( 543): Sending off request.
> D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_OFF
> D/BluetoothManagerService( 543): Calling onBluetoothServiceDown callbacks
> D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceDown() to
> 5 receivers.
> D/BluetoothAdapterService( 1032): Cleaning up adapter native....
> D/BluetoothAdapterService( 1032): Done cleaning up adapter native....
> D/BluetoothAdapterService(746876560)( 1032): ****onDestroy()********
>
> -------------------End---------------------
>
> For Scenario 1 , I am trying to build rfkill tool for android(Currently no
> success). Can we change the state from code by opening rfkill path
> "/sys/class/rfkill/rfkill0/state" and write 1 to enable?
>
> But scenario 3 looks like I missed some configuration.
>
> What could be the problem?
>
> Regards,
> KP
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>



Hi All,


I analysed the Android flow and found that Android System server will
initialize and check for bluetooth hardware on during Boot. So if we
connect the USB BT Dongle after boot Android BT service may not identify
it.
May be this is the reason because of which scenario 3 (Boot Android device
and then plug the USB BT Dongle.Then Turn on from Bluetooth setting) is
not working.
This is my understanding. Correct me If I am wrong.

Anyone tried USB BT pnp on android?

Regards,
KP

2015-09-08 09:51:56

by krishnaks

[permalink] [raw]
Subject: Re: USB BT gives problem If device plugged during boot to platform.

>> Hi,
>>
>>> I am porting bluez 5.33 to android kitkat 4.4.3.I am using USB based
>>> Bluetooth device. I referred instruction in
>>> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/android/README and
>>> able to build.
>>> After botting Android image with USB dongle connected and type
>>> "hciconfig
>>> hci0 up" on console, It is throwing following error.
>>> Can't init device hci0: Unknown error 132 (132)
>>>
>>> If I Type hciconfig -a . It gives following.
>>> hci0: Type: BR/EDR Bus: USB
>>> BD Address: 5C:F3:70:6C:5E:FB ACL MTU: 1021:8 SCO MTU: 64:1
>>> DOWN
>>> RX bytes:547 acl:0 sco:0 events:27 errors:0
>>> TX bytes:384 acl:0 sco:0 commands:27 errors:0
>>> Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
>>> Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
>>> Link policy: RSWITCH SNIFF
>>> Link mode: SLAVE ACCEPT
>>>
>>>
>>>
>>> But If I unplug and plug USB dongle, and then try same command
>>> (hciconfig
>>> hci0 up), It works. Even "hcitool scan" command also working after
>>> that.
>>>
>>> Why 1st time not working when USB dongle is connected?
>>> Also when I check Bluez debug log in logcat.
>>> I am getting one error log when USB dongle connected during boot.
>>> E/bluetoothd( 841): Failed to set mode: Blocked through rfkill (0x12).
>>
>> I think that blocked through rfkill is pretty obvious. Check with the
>> rfkill tool on what the current settings are. For some reason it seems
>> Bluetooth is blocked by default. And I remember there were some kernel
>> patches for this. Just do not remember the details.
>>
>> Regards
>>
>> Marcel
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-bluetooth"
>> in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
> Hi,
>
> Thanks for the reply.
>
> In my busybox utils rfkill is not enabled. If I enable it and try "rfkill
> unblock" is that will be enough? or I need to search for Kernel patch that
> fixes this rfkill block issue?

Hi,

By Analysing I found 3 scenarios and only in one scenario BT is working.
Scenario 1 : Connect USB BT Dongle and then boot the android device.Then
Turn on from Android Bluetooth settings

Result: Not working. Rfkill block error.
E/bluetoothd( 868): Failed to set mode: Blocked through rfkill (0x12)

Scenario 2: Connect USB BT Dongle and boot. Then unplug and plug again.
Then Turn on from Android Bluetooth settings.

Result: Working: BT turning on and scanning BT/BLE devices.

Scenario 3: Boot Android device and then plug the USB BT Dongle.Then Turn
on from Android Bluetooth settings.

Result: Not working. Here we are not getting any debug prints from bluez.
Whether we need to rerun the init.bluetooth.rc as BT Dongle was not
connected during boot.
>From Logcat,observing following error messages
IBluetooth.configHciSnoopLog return false
Bluetooth module is not loaded

Logcat:

-------------------Start-------------------
D/BluetoothManagerService( 543): enable(): mBluetooth =null mBinding =
false
D/BluetoothManagerService( 543): Message: 1
D/BluetoothManagerService( 543): MESSAGE_ENABLE: mBluetooth = null
D/BluetoothAdapterService( 1032): REFCOUNT: CREATED. INSTANCE_COUNT2
D/BluetoothAdapterState( 1032): make
I/BluetoothAdapterState( 1032): Entering OffState
D/BluetoothManagerService( 543): BluetoothServiceConnection:
com.android.bluetooth.btservice.AdapterService
D/BluetoothManagerService( 543): Message: 40
D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 1
E/BluetoothManagerService( 543): IBluetooth.configHciSnoopLog return false
D/BluetoothManagerService( 543): Calling onBluetoothServiceUp callbacks
D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceUp() to 5
receivers.
D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_ON
D/BluetoothAdapterProperties( 1032): Setting state to 11
I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 10-> 11
D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
receivers.
D/BluetoothManagerService( 543): Message: 60
D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
prevState = 10, newState=11
D/BluetoothManagerService( 543): Bluetooth State Change Intent: 10 -> 11
D/BluetoothBondStateMachine( 1032): make
D/BluetoothMapService( 1032): onReceive
I/BluetoothBondStateMachine( 1032): StableState(): Entering Off State
D/HeadsetService( 1032): Received start request. Starting profile...
D/HeadsetStateMachine( 1032): make
E/BluetoothHeadsetServiceJni( 1032): Bluetooth module is not loaded
D/A2dpService( 1032): Received start request. Starting profile...
V/Avrcp ( 1032): make
E/BluetoothAvrcpServiceJni( 1032): Bluetooth module is not loaded
D/A2dpStateMachine( 1032): make
E/BluetoothA2dpServiceJni( 1032): Bluetooth module is not loaded
D/A2dpStateMachine( 1032): Enter Disconnected: -2
D/HidService( 1032): Received start request. Starting profile...
E/BluetoothHidServiceJni( 1032): Bluetooth module is not loaded
D/HealthService( 1032): Received start request. Starting profile...
I/BluetoothAdapterState( 1032): Entering PendingCommandState State:
isTurningOn()=true, isTurningOff()=false
E/BluetoothHealthServiceJni( 1032): Bluetooth module is not loaded
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.hdp.HealthService
D/PanService( 1032): Received start request. Starting profile...
D/BluetoothPanServiceJni( 1032): initializeNative(L110): pan
E/BluetoothPanServiceJni( 1032): ## ERROR : initializeNative(L115):
Bluetooth module is not loaded##
D/BluetoothTethering( 543): got CMD_CHANNEL_HALF_CONNECTED
E/BluetoothTethering( 543): Trying to set mAsyncChannel twice!
D/BtGatt.DebugUtils( 1032): handleDebugAction() action=null
D/HeadsetPhoneState( 1032): sendDeviceStateChanged. mService=0 mSignal=0
mRoam=0 mBatteryCharge=5
D/BtGatt.GattService( 1032): Received start request. Starting profile...
D/BtGatt.GattService( 1032): start()
E/BtGatt.JNI( 1032): ERROR: void android::initializeNative(JNIEnv*,
jobject)(L694): Bluetooth module is not loaded##
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.hdp.HealthService
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.hdp.HealthService
D/BluetoothMapService( 1032): Received start request. Starting profile...
D/BluetoothMapService( 1032): start()
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.map.BluetoothMapService
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.map.BluetoothMapService
D/BluetoothAdapterService( 1032): Profile still not
running:com.android.bluetooth.map.BluetoothMapService
D/BluetoothAdapterState( 1032): CURRENT_STATE=PENDING, MESSAGE = STARTED,
isTurningOn=true, isTurningOff=false
E/BluetoothAdapterState( 1032): Error while turning Bluetooth On
D/BluetoothAdapterProperties( 1032): Setting state to 10
I/BluetoothAdapterState( 1032): Bluetooth adapter state changed: 11-> 10
D/BluetoothAdapterService( 1032): Broadcasting updateAdapterState() to 1
receivers.
I/BluetoothAdapterState( 1032): Entering OffState
D/BluetoothManagerService( 543): Message: 60
D/BluetoothManagerService( 543): MESSAGE_BLUETOOTH_STATE_CHANGE:
prevState = 11, newState=10
D/BluetoothManagerService( 543): Broadcasting
onBluetoothStateChange(false) to 10 receivers.
D/BluetoothA2dp( 543): onBluetoothStateChange: up=false
D/BluetoothHeadset( 543): onBluetoothStateChange: up=false
D/BluetoothPbap( 851): onBluetoothStateChange: up=false
D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
D/BluetoothMap( 851): onBluetoothStateChange: up=false
D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
D/BluetoothHeadset( 839): onBluetoothStateChange: up=false
D/BluetoothInputDevice( 851): onBluetoothStateChange: up=false
D/BluetoothManagerService( 543): Bluetooth State Change Intent: 11 -> 10
E/BluetoothManagerService( 543): recoverBluetoothServiceFromError
D/BluetoothMapService( 1032): onReceive
D/DockEventReceiver( 851): finishStartingService: stopping service
W/ContextImpl( 851): Calling a method in the system process without a
qualified user: android.app.ContextImpl.startService:1487
android.content.ContextWrapper.startService:494
android.content.ContextWrapper.startService:494
com.android.settings.bluetooth.DockEventReceiver.beginStartingService:134
com.android.settings.bluetooth.DockEventReceiver.onReceive:115
D/BluetoothManagerService( 543): Sending off request.
D/BluetoothAdapterState( 1032): CURRENT_STATE=OFF, MESSAGE = USER_TURN_OFF
D/BluetoothManagerService( 543): Calling onBluetoothServiceDown callbacks
D/BluetoothManagerService( 543): Broadcasting onBluetoothServiceDown() to
5 receivers.
D/BluetoothAdapterService( 1032): Cleaning up adapter native....
D/BluetoothAdapterService( 1032): Done cleaning up adapter native....
D/BluetoothAdapterService(746876560)( 1032): ****onDestroy()********

-------------------End---------------------

For Scenario 1 , I am trying to build rfkill tool for android(Currently no
success). Can we change the state from code by opening rfkill path
"/sys/class/rfkill/rfkill0/state" and write 1 to enable?

But scenario 3 looks like I missed some configuration.

What could be the problem?

Regards,
KP

2015-09-04 12:45:12

by krishnaks

[permalink] [raw]
Subject: Re: StartLescan rerturns false

> Hi,
>
> On Thursday 03 of September 2015 10:00:14 [email protected]
> wrote:
>> > Hi,
>> >
>> > I have ported bluez to Android Kitkat 4.4.3 and I am testing Bluetooth
>> Low
>> > energy from android application.
>> > BluetoothAdapter's method startLeScan returns false during scanning
>> BLE
>> > devices.
>> > register-client method is getting called in hal-gatt.c. But looks like
>> > "scanStarted" function is returning false.
>> >
>> > Have anyone faced this issue.
>> >
>> > Thanks in advance
>> > KP
>>
>> Hi All,
>>
>> From the Android Logcat I found that GATT JNI is failing to initialize
>>
>> E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
>> jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##
>>
>> Is this could be the reason for startlescan to return false?
>
> Yes, profile must be initialized if you want to use it.
>
>> Regards,
>> KP
>>
>> ----------------Log----------------------
>> I/BtGatt.JNI( 833): void android::classInitNative(JNIEnv*,
>> jclass)(L684):
>> classInitNative: Success!
>> D/BtGatt.DebugUtils( 833): handleDebugAction() action=null
>> D/BtGatt.GattService( 833): Received start request. Starting profile...
>> D/BtGatt.GattService( 833): start()
>> D/BlueZ ( 833):
>> external/bluetooth/bluez/android/hal-bluetooth.c:get_profile_interface()
>> gatt
>> D/BlueZ ( 833): external/bluetooth/bluez/android/hal-gatt.c:init()
>> E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
>> jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##
>> I/ActivityManager( 523): Start proc com.android.mms for broadcast
>> com.android.mms/.transaction.MmsSystemEventReceiver: pid=897
>> D/BLE ( 1233): Before LE Scan statusfalse
>> D/BluetoothAdapter( 1233): startLeScan(): null
>> D/BtGatt.GattService( 1059): registerClient123() -
>> UUID=e7db8dc6-dc0b-41ff-b036-41b761fd4837
>> I/audio_hw_primary( 188): start_output_stream... 2016291600, device 2
>> W/audio_hw_primary( 188): card 1, port 0 device 0x2
>> W/audio_hw_primary( 188): rate 48000, channel 2 period_size 0xc0
>> W/audio_hw_primary( 188): do_out_standby... 2016291600
>> D/BLE ( 1233): After LE Scan statusfalse
>> --------------Log--------------
>
> There is no daemon logs here but my guess would be that required crypto
> stuff
> is missing in kernel. Check "Linux Kernel requirements" section in
> android/README for list of required kernel options.
>
> --
> BR
> Szymon Janc
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

Hi,

Thanks for your suggestion. That was the problem.
CONFIG_CRYPTO_USER_API_HASH was not enabled to Kernel. Now BLE scanning is
working.

Thanks a lot.

Regards,
KP



2015-09-03 14:25:43

by Szymon Janc

[permalink] [raw]
Subject: Re: StartLescan rerturns false

Hi,

On Thursday 03 of September 2015 10:00:14 [email protected] wrote:
> > Hi,
> >
> > I have ported bluez to Android Kitkat 4.4.3 and I am testing Bluetooth Low
> > energy from android application.
> > BluetoothAdapter's method startLeScan returns false during scanning BLE
> > devices.
> > register-client method is getting called in hal-gatt.c. But looks like
> > "scanStarted" function is returning false.
> >
> > Have anyone faced this issue.
> >
> > Thanks in advance
> > KP
>
> Hi All,
>
> From the Android Logcat I found that GATT JNI is failing to initialize
>
> E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
> jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##
>
> Is this could be the reason for startlescan to return false?

Yes, profile must be initialized if you want to use it.

> Regards,
> KP
>
> ----------------Log----------------------
> I/BtGatt.JNI( 833): void android::classInitNative(JNIEnv*, jclass)(L684):
> classInitNative: Success!
> D/BtGatt.DebugUtils( 833): handleDebugAction() action=null
> D/BtGatt.GattService( 833): Received start request. Starting profile...
> D/BtGatt.GattService( 833): start()
> D/BlueZ ( 833):
> external/bluetooth/bluez/android/hal-bluetooth.c:get_profile_interface()
> gatt
> D/BlueZ ( 833): external/bluetooth/bluez/android/hal-gatt.c:init()
> E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
> jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##
> I/ActivityManager( 523): Start proc com.android.mms for broadcast
> com.android.mms/.transaction.MmsSystemEventReceiver: pid=897
> D/BLE ( 1233): Before LE Scan statusfalse
> D/BluetoothAdapter( 1233): startLeScan(): null
> D/BtGatt.GattService( 1059): registerClient123() -
> UUID=e7db8dc6-dc0b-41ff-b036-41b761fd4837
> I/audio_hw_primary( 188): start_output_stream... 2016291600, device 2
> W/audio_hw_primary( 188): card 1, port 0 device 0x2
> W/audio_hw_primary( 188): rate 48000, channel 2 period_size 0xc0
> W/audio_hw_primary( 188): do_out_standby... 2016291600
> D/BLE ( 1233): After LE Scan statusfalse
> --------------Log--------------

There is no daemon logs here but my guess would be that required crypto stuff
is missing in kernel. Check "Linux Kernel requirements" section in
android/README for list of required kernel options.

--
BR
Szymon Janc

2015-09-03 14:00:14

by krishnaks

[permalink] [raw]
Subject: Re: StartLescan rerturns false

> Hi,
>
> I have ported bluez to Android Kitkat 4.4.3 and I am testing Bluetooth Low
> energy from android application.
> BluetoothAdapter's method startLeScan returns false during scanning BLE
> devices.
> register-client method is getting called in hal-gatt.c. But looks like
> "scanStarted" function is returning false.
>
> Have anyone faced this issue.
>
> Thanks in advance
> KP
>
Hi All,

>From the Android Logcat I found that GATT JNI is failing to initialize

E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##

Is this could be the reason for startlescan to return false?

Regards,
KP

----------------Log----------------------
I/BtGatt.JNI( 833): void android::classInitNative(JNIEnv*, jclass)(L684):
classInitNative: Success!
D/BtGatt.DebugUtils( 833): handleDebugAction() action=null
D/BtGatt.GattService( 833): Received start request. Starting profile...
D/BtGatt.GattService( 833): start()
D/BlueZ ( 833):
external/bluetooth/bluez/android/hal-bluetooth.c:get_profile_interface()
gatt
D/BlueZ ( 833): external/bluetooth/bluez/android/hal-gatt.c:init()
E/BtGatt.JNI( 833): ERROR: void android::initializeNative(JNIEnv*,
jobject)(L718): Failed to initialize Bluetooth GATT, status: 1##
I/ActivityManager( 523): Start proc com.android.mms for broadcast
com.android.mms/.transaction.MmsSystemEventReceiver: pid=897
D/BLE ( 1233): Before LE Scan statusfalse
D/BluetoothAdapter( 1233): startLeScan(): null
D/BtGatt.GattService( 1059): registerClient123() -
UUID=e7db8dc6-dc0b-41ff-b036-41b761fd4837
I/audio_hw_primary( 188): start_output_stream... 2016291600, device 2
W/audio_hw_primary( 188): card 1, port 0 device 0x2
W/audio_hw_primary( 188): rate 48000, channel 2 period_size 0xc0
W/audio_hw_primary( 188): do_out_standby... 2016291600
D/BLE ( 1233): After LE Scan statusfalse
--------------Log--------------


2015-09-02 12:24:41

by krishnaks

[permalink] [raw]
Subject: Re: StartLescan rerturns false

Hi,

I have ported bluez to Android Kitkat 4.4.3 and I am testing Bluetooth Low
energy from android application.
BluetoothAdapter's method startLeScan returns false during scanning BLE
devices.
register-client method is getting called in hal-gatt.c. But looks like
"scanStarted" function is returning false.

Have anyone faced this issue.

Thanks in advance
KP