PieterG
Posts: 7
Joined: Thu Nov 10, 2016 4:41 pm

Headless Blue tooth access point as USB Mass Storage Device

Tue Jan 23, 2018 2:27 pm

A short introduction.
Some older car audio systems allow USB connection to play music from mobile devices. The protocol used in older systems is Mass Storage Device.
Since Android 4, Android phones no longer support that without rooting and modding. (Thank you Google :( ). Now they implemented Media Transfer Protocol and Photo Transfer Protocol (MTP and PTP) which is not supported by older car audio systems.

Now I saw the Pi Zero W. That brought me to the following idea.

Have a pi zero w connected to the usb connection of the car audio system acting as a mass storage device.
Let the same pi zero w connect as a headless device to one (or more) smartphones and automount their media folders to a smartlinked folder on the pi zero w. 1. fully headless pass key is fixed, to be typed or checked on the phone only.

Now googling around gives me a huge bunch of results. At least I found some on the Mass Storage, but I could not find anything useful (yet) on the bluetooth connectivity.

If someone could point me into the right direction, I would be very happy.

User avatar
scruss
Posts: 2475
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Headless Blue tooth access point as USB Mass Storage Device

Tue Jan 23, 2018 3:39 pm

I think you're looking for the File Transfer Profile Bluetooth Profile. I don't know how widely supported it is.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
thagrol
Posts: 1834
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Headless Blue tooth access point as USB Mass Storage Device

Wed Jan 24, 2018 12:32 am

The mass storage gadget doesn't safely support access from both sides of the USB link unless both devices are accessing it read only.

This is because neither side can tell the other that it has made changes, both sides use caching, both expect exclusive access, and both require low level access.

As well as the above, the filesystem you're exporting must be one that the USB host can understand. For most consumer devices that's FAT32 (possibly xFAT, or NTFS but not as likely).

Also, the mass storage gadget uses a backing store that must be either a disk partition or a file (which presents to the USB host as a disk/partition). It can't be passed a directory.

So, to do what you want, you need to present the phone's storage to the mass storage gadget as a FAT32 formatted block device. That's not impossible but isn't trivial either

By using one of the storage area network protocols I've done something similar to give a TV with USB host access to my NAS (see here: https://www.instructables.com/id/NAS-Ac ... d-Devices/). You might be able to adapt that to your use case if you use the bluetooth personal area network profile, you can partition your phone's storage apropriately, and your phone(s) have server side drivers for the SAN protocol used.

Sorry to rain on your parade, but it's better that you know this before trying something that may corrupt the data on your phones.
This space unintentionally left blank.

PieterG
Posts: 7
Joined: Thu Nov 10, 2016 4:41 pm

Re: Headless Blue tooth access point as USB Mass Storage Device

Thu Jan 25, 2018 10:43 am

As I understand, as the mobile phone does not support Mass Storage Device

1. connect with bluetooth using File Transfer Profile Bluetooth Profile (goop, obex)
2. I should only mount it as read only.
3. The partition should be fat32 at best

but can it actually be powered from the usb to go port? Or does it really need powered using a second connection on the second micro usb socket?

User avatar
thagrol
Posts: 1834
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Headless Blue tooth access point as USB Mass Storage Device

Thu Jan 25, 2018 4:43 pm

You should be able to power a pi zerow from a host USB port.

The real problem you're going to have is taking a file based interface (bluetooh ftp/obex) and presenting it to the host as a block device (FAT32 disk). These are very different things and work in different ways.

In brief:
Bluetooth ftp:
  • Client: give me a list of your files
  • Server: here you go
  • Client: give me file f
Mass Storage (USb stick etc)
  • OS: give me n bytes of data starting at address a
  • device: here you go
    OS intreprets data as list of file names, start addresses, and sizes, finds start address and length of desired file (This is a simplification, data in any given file can be spread across the disk rather than in a single block)
  • OS: give me n bytes starting at address f
The device has no concept of files, it only knows about bytes, blocks, and addresses.

To do what you want to you'll to have to convert between these two methods, in both directions, on the fly. It's not impossible but it is non-trivial. You'd also need to do it fast enough that playback doesn't suffer.

That conversation would be something like:
  • Headunit:give me n bytes of data starting at address a
  • pi: Bluetooth device give me a list of your files
  • Bluetooth device: here you go
    pi converts list to fake FAT32 data
  • pi: headunit, here you go
  • headunit: give me n bytes starting address a
    pi converts a to back to a filename
  • pi: bluetooth, give me file f
  • bluetooth: here you go
  • pi: headunit, here you go
It's more complicated than that, especially when caching and fetching files in chunks is involved but you get the idea. The USB mass storage gadget won't do any of that for you, all it does is provide an interface between the USB protocol and a linux block device.

In addition to that, short of faking a remove and re-insert event, there is no way for the zero to inform the head unit (the USB host) that its contentes have changed. I'd expect such a method to stop audio and trigger a full rescan of the storage.

Frankly, assuming that your phones can act as mass storage devices over USB (and every android phone I've used could) you'd find it simpler just to plug the phone into the head unit via a normal micro-USB cable.
This space unintentionally left blank.

PieterG
Posts: 7
Joined: Thu Nov 10, 2016 4:41 pm

Re: Headless Blue tooth access point as USB Mass Storage Device

Fri Jan 26, 2018 8:46 pm

Frankly, assuming that your phones can act as mass storage devices over USB (and every android phone I've used could) you'd find it simpler just to plug the phone into the head unit via a normal micro-USB cable.
as I wrote earlier.. someone at Google/Android decided to remove the mass storage feature and replace with MTP / PTP which by windows is treated as mass storage thanks to some driver.

a somewhat older car audio system with usb connection cannot handle MTP / PTP thus fails at connecting over USB

meanwhile I got hold of an iPhone 6.. same problem... no mass storage device... error messages galore...

to connect to older car audio systems using the USB connect does require mass storage device features.

The only way I can make an android phone act as mass storage device is root it and then I can add the feature... I can do that of course on my own phone, but can hardly ask the soccer team mates of my kids to root their devices.. and that is the goal of all this..

User avatar
thagrol
Posts: 1834
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Headless Blue tooth access point as USB Mass Storage Device

Fri Jan 26, 2018 11:09 pm

PieterG wrote:
Fri Jan 26, 2018 8:46 pm

The only way I can make an android phone act as mass storage device is root it and then I can add the feature... I can do that of course on my own phone, but can hardly ask the soccer team mates of my kids to root their devices.. and that is the goal of all this..
In which case, unless you're a C/C++ programmer with experience of linux device drivers and low level filesystem access/drivers you're going to be out of luck.

I'm not one of those, I'm afraid.

And you're right, MTP/PTP won't cut it for much the same reason that bluetooth FTP won't. Sorry for my confusion there.

The only quick and easy solution left that I can think of is to look into bluetooth audio receivers if your head unit has an aux input or fm transmitters if it doesn't. These won't allow control from the head unti but will get music from a random phone into it.

As a final thought, if your head unit does have an aux input, you could skip bluetooth entirely and just go with a sufficiently long cable.
This space unintentionally left blank.

Return to “Beginners”