5

I am currently trying to connect a Raspberry Pi and an iOS device via Bluetooth. Using BTLE and the CBCentralManager I am able to do this - I can connect to the Pi and share data.

My problem is that for my purpose I need the devices to have an IP - which, as far as I know, is only possible using a PAN (Personal Area Network) bluetooth profile. iOS does support this with the new Multipeer Connectivity Framework and it works when connecting two iOS devices, one using MCNearbyServiceBrowser and the other using MCNearbyServiceAdvertiser. After the connection was made both devices have a network interface with an IP. But now I have to get the Rasperry Pi into that scenario - and I cannot find any way to make the Pi join the PAN.

Does anyone have any clues if this is somehow possible, where to start looking, if there is a good explanation about the communication in a PAN or something similar? Could there maybe even be a framework that does something like that? I am happy for any leads and advices.

ThomasW
  • 16,981
  • 4
  • 79
  • 106
BlackWolf
  • 5,239
  • 5
  • 33
  • 60

1 Answers1

5

The Multipeer Connectivity Framework probably is probably based on a proprietary protocol as I have nowhere seen that it implements PAN. It's only similar to it. As you mention, the list of supported profiles contains PAN as well with the following note:

Depending on the Bluetooth accessory, you may experience slight variations in profile functionality. These variations are governed by the accessory manufacturer, not the iOS device.

So in theory PAN is supported as is, and you should be able to connect with an arbitrary device that supports this profile. I connected my Android phone to my iPhone with the Personal Hotspot on the iPhone and the Android could use the shared internet connection without any issues.

I found the Raspberry Pi Bluetooth iPhone Tethering tutorial that seems to describe exactly what you are trying to do. For future reference I copy the steps here:

Install the bluetooth packages

sudo aptitude install bluetooth bluez-utils bluez-compat

Pair the devices, this is the tricky part

pi@raspberrypi ~ $ hcitool scan
Scanning ...
    18:34:51:55:B0:D8   Fanboy ][
pi@raspberrypi ~ $
pi@raspberrypi ~ $ grep KeyboardDisplay /usr/bin/bluez-simple-agent 
    capability = "KeyboardDisplay"
pi@raspberrypi ~ $ sudo perl -i -pe 's/KeyboardDisplay/DisplayYesNo/' /usr/bin/bluez-simple-agent
pi@raspberrypi ~ $ grep DisplayYesNo /usr/bin/bluez-simple-agent
    capability = "DisplayYesNo"
pi@raspberrypi ~ $ 
pi@raspberrypi ~ $ sudo bluez-simple-agent hci0 18:34:51:55:B0:D8
RequestConfirmation (/org/bluez/18868/hci0/dev_18_34_51_55_B0_D8, 160178)
Confirm passkey (yes/no): yes
Release
New device (/org/bluez/18868/hci0/dev_18_34_51_55_B0_D8)
pi@raspberrypi ~ $
pi@raspberrypi ~ $ sudo bluez-test-device trusted 18:34:51:55:B0:D8 yes

Turn on the Personal Hotspot

pi@raspberrypi ~ $ echo "echo 'iface bnep0 inet dhcp' >> /etc/network/interfaces" | sudo sh
pi@raspberrypi ~ 

$ sudo pand -c 18:34:51:55:B0:D8 -role PANU --persist 30

Enjoy

pi@raspberrypi ~ $ ifconfig bnep0
bnep0     Link encap:Ethernet  HWaddr e0:91:53:61:0f:74  
          inet addr:172.20.10.10  Bcast:172.20.10.15  Mask:255.255.255.240
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:14 errors:0 dropped:0 overruns:0 frame:0
      TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:4426 (4.3 KiB)  TX bytes:802 (802.0 B)

All credits go to http://www.wolfteck.com/ for providing these detailed instructions.

allprog
  • 16,540
  • 9
  • 56
  • 97
  • 1
    thank you very much. unfortunately, I cannot test this until the beginning of next week, but I will report back as soon as I did. – BlackWolf Mar 20 '14 at 07:43
  • 1
    Note that on iOS (unlike Android), you need to enable mobile data in order to activate personal hotspot. – Etan Mar 20 '14 at 20:42
  • Well, I finally came down to testing this: It does indeed work (more or less), but the problem I am having is that I want to _programmatically_ connect to a bluez PAN from an iOS device, and I still can't see how I can do that? In fact, usingt `MCNearbyServiceBrowser` does not seem to be noticed by the pi at all. Can I somehow sniff the BT packets sent by the iphone to maybe find out more about this? – BlackWolf Mar 25 '14 at 00:37
  • You won't be able to do that. Only the user can modify any network settings. – allprog Mar 25 '14 at 06:34
  • 1
    The Multipeer Framework is a proprietary, closed source protocol. Additionally, it requires the MFi authenticator chip to make such a connection (hence only iOS devices are connectable.) So even if you could reverse engineer the protocol, you wouldn't be able to make any connections. On a non-Jailbroken iOS device the way I described is the only thing you can do, anything else with bluetooth requires MFi. – allprog Mar 25 '14 at 06:40
  • That's too bad... considering I am developing an internal app and can use private APIs like the `BluetoothManager`, is there any good way to do this? An alternative could be to manually open an ad-hoc wifi network using private APIs, but I couldn't find anything useful on how to do that so far... – BlackWolf Mar 25 '14 at 13:16
  • I haven't looked into the private APIs. It may be possible to do that. You should ask this in a different question I'm interested in learning something new too. Btw, do you think I answered this question? If so, then please accept it. Thanks. – allprog Mar 25 '14 at 14:13
  • @allprog How do you know that the Multipeer Framework requires an MFi chip? Does this also apply in the Wifi-only (i.e. non-Bluetooth) operation mode? – flo von der uni Apr 21 '15 at 18:16
  • Only the supported bluetooth profiles need no authenticator chip https://support.apple.com/hu-hu/HT204387. MC is unfortunately not listed there. – allprog Apr 22 '15 at 05:20