USB Host Support for Custom Devices - Galaxy S II Android Development

The SGS2 supports USB OTG which means it can play host to certain low-powered USB devices. Unfortunately the kernel is configured with a whitelist that means it will only connect to HIDs, printers, PTP cameras and mass storage devices.
I wanted to begin developing an application using custom (vendor specific) USB hardware and so started experimenting to see if it was possible. There is a full description of how I went about it on my blog. To summarise, one of the ways to enable vendor specific USB devices is to edit the file "drivers/usb/core/sec_whitelist.h" and add the following to both whitelist tables:
Code:
{ USB_DEVICE_INFO(0xff, 0x0, 0x0) }, /* vendor specific USB devices */
There are two reasons for this post, the first is to provide information to help others that may want to do the same thing. The second is to try and encourage kernel modders to include my changes (or disable the whitelists altogether) thereby providing application developers the means with which to communicate with custom hardware.
Regards,
Dan

Nice idea, I may be completely wrong, but if you remove the white list it, will accept other hardware? or is it dependant on it being there?
Sent from my GT-I9100 using Tapatalk

Does you also test Google ADK ??
Do you know if it would work with the S2 ?

@MacaronyMax: As I mentioned in my blog post, it is possible to disable the whitelist entirely via the kernel options which I assume would allow any device to connect, but I have not tested this and so am unsure.
@xlanhackerx: The ADK relies on accessories that have been designed to act as host and use an Android specific protocol, whereas I am interested in the SGS2 acting as host so that I can connect custom third-party slave devices to it. Therefore I have not looked at the ADK at all and I do not have the hardware available to even play with it.
Regards,
Dan

Thank you. Maybe a custom ROM has it built in?
Thank you so much terranim for this discovery, and for posting it.
I have been struggling on that for a week now, not understanding why my driver was apparently not even called.
I was thinking it could exist a ROM that has this whitelist removed... anyone has a clue? (Lite'ning 6.1 / ninphetamin 2.0.5 or .11 have is using sec_whitelist.h)

I don't think that any kernel developers have disabled this whitelist yet! However there is now another major problem: In the latest ROM from Samsung it is reported that they have removed the USB host related libraries in the Android SDK!
My hack to the kernel will still work and allow devices to be connected, but we will no longer be able to communicate with custom USB devices via an Android application (unless we write a C library to talk to the devices directly or via libusb).
Hopefully developers will restore these libraries in their own custom ROMS.

I guess I am not too far from running this whitelist with your new line on a home compiled version of ninphetamine... see http://forum.xda-developers.com/showpost.php?p=18123923&postcount=2828 and http://forum.xda-developers.com/showpost.php?p=18123923&postcount=2833
I just got to to compile completely a minute ago, and will test it on Thursday.
I think I will stick to custom ROMs / kernel now... and possibly some I compile myself.
Did you read about libftdi? That could help you. Also that Samsung removed USB API might not harm as long as you use a serial port created by the serialusb driver.
edit / ps: nice to work in a team

guys,
is there any chance this USB Host mode could work with a headphones USB DAC/Amp like the FiiO E7?
I really envy the iPod/Pad/Phone users and their ability to have pure sound of their devices while on the go. I know we have HDMI/MHL but sadly there are no headphones amps using this link

I would be interested in this as well.

it is correct that Samsung have removed the USB Host API,
As far as I can tell, they never intended to leave it there to begin with, but I do know that the particular API was introduced in API 11 (Honeycomb).
Sent from my GT-I9100 using Tapatalk

What kernel options are required for this and what is needed to test connectivity? I have an older Galaxy S device and I'm trying to reproduce what you've done here. I just got an ADK for christmas and I've been working with Cyanogenmod kernel source in an attempt to get things operating. From what I can see I need a kernel driver. It would appear that it's begining to recognize that *something* is plugged in, but it's not enumerating.
Anything you can show me would be helpful. What do you see in dmesg when ADK or any other device is connected?

Hi. I know this is an old thread but I want to know if there is some patch to enable USB DACs on the S2. I can not find anything that can enable this like the S3. If some one knows some thing please reply.
Thanks

Related

[Q] X10i USB modes (HOST, OTG...) ?

Hi,
there is really one thing that is still for me - USB HOST/OTG. I investigating long time X10i`s capability of usb host mode.
I found that chipset really supports it and in virtual device filesystem in /dev and /sys are devices usb hid and usb hub. So I really thing that Xperia X10i has host capability.
I also found, that usb ehci drivers are not present, so this feature can`t work of course. Currently I am looking for sources to compile these drivers (I thing they must be compatible with stock kernel...) and push them into device.
I dont know, if it will work or not, but want to ask, if anybody has handling about this function yet ?
Dont want to do something which is completely impossible
Thanx
any progress??
xpaa said:
any progress??
Click to expand...
Click to collapse
Nothing real - but found interesting circuits in X10`s printed circuit schematics - near chip FSUSB31 switch. There are also control points on the bottom of the mainboard (under manufacturer`s label) which seems to be usb communication interface...
But firstly need a QSD8250 CPU pinout, which should be more difficult
Stay tuned
OK, OK it took a lot of time but - it should work. Hardware is prepared
But need source code for this kernel:
2.6.29-modFXP-DooMKernel-v04b
Because I have to build modules for it. Hate Android, which needs diferrent modules for different builds...
Anyone know where I could downloaded sources? I dont want to PM directly to Doomlord - dont like annoying devs...
EDIT: Driver modules built - but no luck with them... Will try some coding, but it seems that contacting Doomlord is inevitable ...

[Q] possible to use modem 3g usb?

it's possible to use modem 3g on usb ?(i'm not interested connecting by phone)
if yes, i will need a drivers?
if i connect usb modem 3g. can i make a call and sent sms? and what app i need to do it?
Funny you should ask, since I was just working on this yesterday...
I've got access to an AT&T USBConnect 881 made by Sierra Wireless that is well known for working on Linux platforms with either kppp or wvdial. I managed to compile the sierra.ko kernel module and it loads fine, detects the modem, and provides the necessary /dev/ttyUSB* interfaces. I have yet to test the "dialing" portion with pppd and the chatscript, but I can't imagine why it wouldn't work.
I'll probably work on it later today and will report back on progress. I don't know of an easy way to integrate the connectivity into the built-in Android system stuff, so for the time being it will all be done via command line with scripts.
There's a long thread in the OG Transformer forum. Whatever they're doing should most likely work (or not) on the Prime.
http://forum.xda-developers.com/showthread.php?t=1151097
so, can i use a usb Modem Huawei E398 4G LTE and it will be works?
agentdr8 said:
Funny you should ask, since I was just working on this yesterday...
I've got access to an AT&T USBConnect 881 made by Sierra Wireless that is well known for working on Linux platforms with either kppp or wvdial. I managed to compile the sierra.ko kernel module and it loads fine, detects the modem, and provides the necessary /dev/ttyUSB* interfaces. I have yet to test the "dialing" portion with pppd and the chatscript, but I can't imagine why it wouldn't work.
I'll probably work on it later today and will report back on progress. I don't know of an easy way to integrate the connectivity into the built-in Android system stuff, so for the time being it will all be done via command line with scripts.
Click to expand...
Click to collapse
I also have a usb modem I would like to use. Do you have any good links/guides on how to compile these modules? I have recently installed Ununtu on my laptop and would like to tinker with this. Thanks!
sajmon1983 said:
so, can i use a usb Modem Huawei E398 4G LTE and it will be works?
Click to expand...
Click to collapse
From what I can see in the running config of the current kernel, it looks like the USB driver for GSM and CDMA modems is already compiled in, and that driver includes support for the E398 according to this.
You'd probably want to search the net to see if there is a chatscript already written for that modem.
---------- Post added at 03:30 PM ---------- Previous post was at 03:18 PM ----------
Nico^APEX said:
I also have a usb modem I would like to use. Do you have any good links/guides on how to compile these modules? I have recently installed Ununtu on my laptop and would like to tinker with this. Thanks!
Click to expand...
Click to collapse
I usually start out by Googling the modem model and the word "linux", since Android is linux to some degree. Once you find out if others have tried it, you try and find which kernel module is needed to support that device. A lot of them are covered by the generic GSM/CDMA usb modem driver, which the TFP kernel should already have support for. Then it's just a matter of plugging it into the usb port, fire up a root shell either via adb or locally via Terminal Emulator/BTEP/ConnectBot and see if it will "dial" out to your cellular provider. Do a "man pppd" search for more info on that.
Unless you have a cross-compiling toolchain setup on your Ubuntu laptop, any kernel modules you build will not be of the proper architecture for the TFP. The modules need to be built for the ARM architecture, not x86. One of the easier ways to having an ARM-based environment to build modules is to run Ubuntu built for ARM on the TFP, and do your module compiling there. This thread shows how to get the running config and also some pointers on building more modules. To get Ubuntu running in a chroot environment on the TFP, look here.
Success!
After tinkering some with the chatscript, I was able to "dial" out on the USBConnect 881 to isp.cingular and browse the net.
If anyone is interested in either the sierra.ko, chatscript/providers file, or anything relating to this hit me up.

[Q] BML one mini android development

Hello friends!
I have a Chinese BML One mini phone (I know it's crappy, but I had no choice), and I'm trying to start an android development with it.
I was aware that it might be hard to find any drivers for that phone, so I decided to use linux (opensuse 13.1) as a development machine (hopefully it requires no extra drivers).
The problem is that device seems to be invisible for the eclipse.
When I do in eclipse "run as - android application" - it says that there is no suitable device found and suggests to create a virtual one.
Usb debugging is on. Phone keyboard is unlocked.
The project is created to run on android 2.2. (The phone says that it is 4, but while digging here on the forum I found that it is really 2.3.5)
Is there any special way of connecting that phone to the PC? Hold secret combination of buttons maybe?
(As far as I know galaxy nexus for example is also invisible for eclipse when you connect it as a flash drive, so you have to connect it as camera.)
The problem is even worse as my laptop is too weak for the development on emulator, so that mobile was the only chance to start android development.
I would be grateful for any answers and links.
Thank you.
Hej hej! Please share any thoughts why it could be? Any suggestion of what to try? Does anyone experienced any device recognition problems with Chinese mobiles on any OS? Is there something special with connection MocorDroid to PC?
What would you try?
Please give me at least a direction to dig.
Thanks
The main issue is that it's not an official Android version and the fact that they modded it to read the wrong Android version there is almost nothing you can do. Mix in the fact that there IS no kernel source code there will not be much you can do at all with development for that device.
Hello, thank you for the answer. You inspired me to search in Chinese internet using google translate, and that is what I've found:
One need to find the vendor and device id using lsusb command
Bus 001 Device 002: ID 1782:5d04 Spreadtrum Communications Inc
These 1782:5d04 is actually a device and vendor id.
Then we need to write it to /etc/udev/rules.d/51-android.rules file in that way:
SUBSYSTEM=="usb",ATTRS{idVendor}=="1782",ATTRS{idProduct}=="5d04",MODE="0666"
And also add "0x1782" without quotes to /home/XXX/.android/adb_usb.ini file.
If you don't have any of these files, create it. Note that 51-android.rules should have 644 permissions.
Than I googled for "0x1782" and found these two links, so I think that problem is not only chinese-fake-android-specific:
stackoverflow. com/questions/9210152/set-up-device-for-development-no-permissions
sudotask. wordpress.com/2013/10/30/how-to-adb-on-open-suse
It could be also problem with permissions like described here:
stackoverflow. com/questions/6484279/detecting-device-for-debugging-adb-does-not-work
So, now I able to use my mobile for Android development! Wait for more garbage in play market!
Thank you!

Why can't Android be installed similar to how you install an OS on a PC?

So Android has been around for a long time, and it is open source. How come we can't easily buy a cell phone with no OS, and install vanilla Android on it?
For comparison, you can buy a PC with no OS, or build one from scratch. They all have somewhat standardized hardware. I can easily install Windows 7, windows 10, Debian, Ubuntu, Linux Mint, etc. I can even install something like the Debian minimal install that doesn't even start with a Desktop environment, and customize exactly what desktop environment I want. Sure you might need to install some wifi drivers and graphics card drivers but they are readily available.
So why is cell phone hardware and Android so different despite being open source and hardware being so competitive? How come I can't just buy a generic phone with no OS, download a Vanilla Android ISO, and install it? Then simply add whatever radio/sensor/gps drivers might be needed, which should be either generic, or else available from the phone hardware manufacturer, similar to how motherboard drivers are available from the motherboard manufacturer.
I realize there are experienced developers out there who are able to make custom roms, but I'm talking about something a general user can do with similar ease to installing and customizing linux on a PC? Why must we generally have to buy exploitable phones to root, overwrite the recovery, and then hopefully find and trust some community rom that some stranger on the forums made?
Well you make a few mistakes. Android is not open source completely. It is under the Apache license. So any code other fixes anyone does they get to keep and dont have to share. Unlike the kernel which is truly open source.
Next your missing a few things. The bootloader for each device which is different unlike with Windows which has a pretty standard one. Also each device has different hardware so the drivers for everything (which are closed sourced as well) will have to be gotten from the oem which they don't share.
Even if you look at the new pc they have locked bootloader so the only things that have ms certs can be flashed.
Thanks for the reply. So the kernel is open source but parts of android are not? I mean, I know some phone developers might make some custom mods that might not be, but isn't the plain Android AOSP code all open source? Isn't installing the AOSP stuff along with any hardware specific drivers enough?
You mention that different phones have different drivers and some are closed source. But PC's have all different hardware. One may have a different wifi chip for example, or sound chip, and the drivers may be closed source, but the motherboard comes with the drivers for the wifi/sound card. So I don't see what is stopping a manufacturer from releasing a phone and include any drivers, like a PC motherboard manufacturer does.
As far as a bootloader, they could just include one or allow a user to install their own. I'm sure open source bootloaders must exist. I mean on a PC you can install whatever bootloader you want, windows, grub, etc. I haven't personally heard of a motherboard having a locked bootloader before where you can't install grub and linux, but if they do exist, at least most motherboards aren't like this.
wildsquirrelfrenzy said:
Thanks for the reply. So the kernel is open source but parts of android are not? I mean, I know some phone developers might make some custom mods that might not be, but isn't the plain Android AOSP code all open source? Isn't installing the AOSP stuff along with any hardware specific drivers enough?
You mention that different phones have different drivers and some are closed source. But PC's have all different hardware. One may have a different wifi chip for example, or sound chip, and the drivers may be closed source, but the motherboard comes with the drivers for the wifi/sound card. So I don't see what is stopping a manufacturer from releasing a phone and include any drivers, like a PC motherboard manufacturer does.
As far as a bootloader, they could just include one or allow a user to install their own. I'm sure open source bootloaders must exist. I mean on a PC you can install whatever bootloader you want, windows, grub, etc. I haven't personally heard of a motherboard having a locked bootloader before where you can't install grub and linux, but if they do exist, at least most motherboards aren't like this.
Click to expand...
Click to collapse
No, even the aosp code is licensed under the Apache. This is why Google gets away with it pushing things they fixed back to the aosp project. It's never that easy even with a nexus device. There are always things that have to be fixed to make it boot.
The difference is unlike pc each device has the hardware drivers outsourced. So say Samsung doesn't really own the drivers they use for BT, wifi, cell radio and things like that. So they can't really distribute them. That's why when you are learning to build it shows you how to pull the files from the device you are building for. This sometimes happens with pc as well. I have a laptop where there are no open source options for the nic card. So if I only run Linux then I have no Internet connection at all. I have to dual boot so Linux will use the windows drivers.
The bootloaders are built per device. There is no open source option yet. Nor will there likely ever be one.
Here is a link about Windows doing it.
http://www.extremetech.com/extreme/...t-mandatory-locks-out-other-operating-systems
Sure you can still buy blank motherboards and load your own os but that doesn't always work.
What I would do is start looking into just what it takes to build the os for a supported device. Which will be a nexus. Then you can see what it takes to make it work with non supported devices.
Google is even making android less 3rd party rom developer unfriendly. Doing things like making root far more difficult to achieve and things of this nature.
Thanks for the detailed explanation. I still hope one day we can just buy empty phones, and install our choice of OS on them, but I guess it may be a long ways away.
Although I did notice according to the oneplus site, they actually allow you to unlock the bootloader and not even void the warranty, and all it takes is a simple command. So hopefully things will be sooner rather than later.
https://oneplus.net/support/answer/will-rooting-or-unlocking-the-bootloader-void-my-warranty
Guess my best alternative for the near future may be to just keep on rooting and try to learn how to make my own ROMS.

Backup/install Wi-Fi device driver?

Is there a way to backup, or transfer the current Wi-Fi device driver from one device to another Rom/firmware?
I'm tinkering with various roms for my android box, and can get everything working but ir remote and Wi-Fi.
Instead of coding it directly into the Rom itself. Yes it comes off as lazy, but thought I would inquire or ask either way.
If it's not possible it's not.. I can accept that and guess I have no choice but to learn how to inject the driver manually. Just need to learn ( any guide you can link to transfer the Wi-Fi/ir settings from one Rom to another would be greatly appreciated )

Categories

Resources