[Android Development on Bada] hunktb:
Bluetooth S8530 investigation

I keep trying, I share some findings (thanks to Volk204 for helping with debug) and some ideas to check in S8530

1. Running RFKILL

I finally found how to run rfkill in badadroid: it is included in last free busybox app from google play. (Badadroid includes BusyBox v1.20.2-jb bionic (2012-11-25 17:47 +0100) and after install I have BusyBox v1.21.0.git (2012-11-29 07:04:19 GMT)

I didn't know this tool, but it has a lot of unix utilities apart from rfkill, as top, nanddump, ...

Tip: by default it is installed in /system/bin, and previous version remains in /system/xbin: I installed it in /system/xbin

busybox rfkill
BusyBox v1.21.0.git (2012-11-29 07:04:19 GMT) multi-call binary.

Usage: rfkill COMMAND [INDEX|TYPE]

Enable/disable wireless devices

Commands:
list [INDEX|TYPE]	List current state
block INDEX|TYPE	Disable device
unblock INDEX|TYPE	Enable device

TYPE: all, wlan(wifi), bluetooth, uwb(ultrawideband),
wimax, wwan, gps, fm

busybox rfkill list
0: bcm4329: bluetooth
Soft blocked: no
Hard blocked: no
1: phy0: wlan
Soft blocked: no
Hard blocked: no
2: brcmfmac-wifi: wlan
Soft blocked: no
Hard blocked: no
3: hci0: bluetooth
Soft blocked: no
Hard blocked: no

Test in S8530: Maybe this output is different in S8530 and rfkill allows to "power on" bluetooth with "busybox unblock 0" ?

2. RFKILL: filesystem and ioctl

Before finding busybox, I was trying to understand the /sys/class/rfkill filesystem structure and info

In my S8500 I found this in /sys/class/rfkill/

rfkill0/name:bcm4329
rfkill1/name:phy0
rfkill2/name:brcmfmac-wifi
rfkill3/name:hci0

rfkill0/type:bluetooth
rfkill1/type:wlan
rfkill2/type:wlan
rfkill3/type:bluetooth

rfkill0/persistent:1
rfkill1/persistent:0
rfkill2/persistent:0
rfkill3/persistent:0

Meaning of this "persistent" file (all have 0 except bluetooth with 1 value)

non-volatile = NV and some relation with nvram_net.txt?

Test in S8530: Maybe there is no 1 value there, bluetooth "not initialised" ?

Info:

https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-rfkill

https://www.kernel.org/doc/Documentation/ABI/obsolete/sysfs-class-rfkill

https://www.kernel.org/doc/Documentation/rfkill.txt

http://m8-android-kernel.googlecode.com/svn/trunk/Documentation/rfkill.txt <<< This second link has more info that previous kernel.org link, and as I am looking how to know the "powered current state", I noticed that

So I decided to investigate ioctl ... it seems it has to be used by code programming, but and I found ioctl command in badadroid

ioctl -h
ioctl [-l <length>] [-a <argsize>] [-rdh] <device> <ioctlnr>
-l <lenght> Length of io buffer
-a <argsize> Size of each argument (1-8)
-r Open device in read only mode
-d Direct argument (no iobuffer)
-h Print help

I have found this example, not related with bluetooth but interesting: with ioctl we can query a device in /dev/...

http://nativedriver.googlecode.com/files/Screenshot_on_Android_Internals.pdf

ioctl -r -l 28 /dev/graphics/fb0 17920
sending ioctl 0x4600 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
return buf: e0 01 00 00 20 03 00 00 e0 01 00 00 e0 15 00 00 00 00 00 00 00 00 00 00 20 00 00 00

Where input 17920 decimal = 0x4600, http://lxr.free-electrons.com/source/include/uapi/linux/fb.h#L13 #define FBIOGET_VSCREENINFO 0x4600, and output E0 01 as "Litte endian" -> 0x01E0=480 decimal ...

So maybe we can use ioctl to query rfkill about bluetooth power state. I have tried some tests as proof of concept (without args) when ioctl doesn't say error... I am unable to understand that, but at least it seems there is the possibility to do "ioctl things" from shell without programming

ioctl -r -l 8 /dev/rfkill 2
sending ioctl 0x2 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
return buf: 00 10 00 00 00 00 00 00

Also "works" (no error) with 0x5201, 0x5421, 0x5450, 0x5451 and 0x5452

http://lxr.free-electrons.com/source/include/uapi/asm-generic/ioctls.h

52 #define FIONBIO 0x5421
81 #define FIONCLEX 0x5450
82 #define FIOCLEX 0x5451
83 #define FIOASYNC 0x5452

I guess rfkill uses ioctl internally and, as rfkill works now in S8500, all this is just curiosity...

3. BTCOEXISTENCE

Some info found about the btc* parameters in nvram_net.txt; it seems not related with the problem of bluetooth not working, just something to avoid interference between wireless and bluetooth

http://wireless.kernel.org/en/users/Documentation/Bluetooth-coexistence

http://bcm-v4.sipsolutions.net/802.11/Bluetooth Coexistance