Read/Write between Mac and iPhone using libusbmuxd - ios

I current use libimobiledevice to work around Mac and iPhone. libusbmuxd is very helpful to get device (iPhone/iPad) information when connects to Mac app through USB.
I want more, I want to read/write data (a file like document, image, video, ...) from Mac to iPhone and vice versa but I can't get any document or tutorial on the Internet guiding how to do it.
Can anyone help me

If you want to transmit data between OSX and iOS via usbmuxd it is basically a two step process:
Start a socket server on an arbitrary port on iOS or tvOS
Open a socket connection to the usbmuxd server on OSX at /var/run/usbmuxd.
After you have done that you will receive some control messages from the usbmuxd server on OSX including events for device attach and detach. Each device that has been attached to the usbmuxd server has a unique device id. This device id in combination with the port of the socket server can be used to bind the socket connection to the socket server.
If you want to save yourself the trouble of implementing this procedure from scratch you can have a look at the following frameworks. They both provide a high level API in Objective-C.
https://github.com/rsms/peertalk
https://github.com/jensmeder/DarkLightning

this is actually quite easy.
Have a further look at https://github.com/libimobiledevice
Especially look at the iFuse example.
libusbmuxd is a library to use the usbmuxd, which tunnels any socket connections on the iOS device over USB to a local socket.
On every iOS device you can find an open socket on port 62078. This is the so-called lockdownd, which is used for many things.
With lockdownd you can start the AFC service (Apple File Conduit), which is a network filesystem service.
libimobiledevice does all of this for you. (Look at libimobiledevice/afc.h, here are all filesystem related functions like reading a file, retrieving a directory, etc.)
Things you have to do:
call lockdown_client_new_with_handshake(..)
call lockdownd_start_service(..) with the "com.apple.afc" service
if your device is jailbroken, you get full filesystem access with the "com.apple.afc2" service, but otherwise the standard service should do well.
By the way: The lockdownd connection works only if your device is unlocked.
Ciao, Arno

Related

Connect to own device's `lockdownd` from an iOS app

My question in a nutshell: Is there a way to create an iOS app running on an iOS device that can connect to and communicate with its own device's lockdownd?
(For the curious who want to know "the why": I would like to use the connection to lockdownd to trigger the installation of apps in .ipa files on the iOS device that have a "local provisioning profile", i.e. a provisioning profile with the flag LocalProvision set to true which means that over-the-air/OTA installations via a web-based installation are prevented by the operating system.)
A little background: You can connect to an iOS device's lockdownd from a second device either
by letting the second device serve as a USB host for the iOS device or
by establishing a wifi-based TCP connection to the iOS device on port 62078.
By using libraries like libimobiledevice, you can then interact with the iOS device - for example to trigger the installation of an app contained in an .ipa file.
What I have already researched & tried:
According to Jon Gabilondo's very good article Understanding usbmux and the iOS lockdown service, lockdownd creates a UNIX domain socket at /var/run/lockdown.sock - unfortunatley however with "privileges 511, which means only root will be able to write to it." (Quote from the article) --> I have therefore not tried accessing/writing to this socket.
lockdownd also opens a TCP endpoint listening on port 62078 in the device's wifi network. --> I have created a small test app that tries to establish a TCP connection to 127.0.0.1:62078. Unfortunatley, the connection attempt fails with the error #1 "Operation not permitted". Same when trying to connect to the IPv4 assigned by the wifi's DHCP server to the iOS device.
What other option could be used to establish a connection to an iOS device's lockdownd from within an app running on that device?

Syncing vast amount of test data to iOS device

In an automated test environment, I have to use 7.5GB of test data, that consists of 170k+ files. Simply copying it with the bundle is too slow (40+ minutes), thus I would like to incrementally sync the contents of the test data folder between the iOS device and the mac. Eg. using the iOS device as a USB drive, and use rsync to sync the contents, but any ideas are welcome. No, I can't jailbreak the device. Basically I want to keep two folders synchronized between an iOS test suite and a mac. Any ideas?
There is a way to do that using USB without jailbreaking your iOS device. The whole setup works via a UNIX socket called usbmuxd that Apple uses to communicate between a USB iOS device and e.g. Xcode or iTunes on a Mac. The iOS device basically opens a TCP server and the OSX app connects to the UNIX socket from which it can obtain a TCP connection to server on the iOS device. After that you can just write and read data over USB using streams at 480MBits.
There are some frameworks under MIT license with example apps for OSX and iOS that allow you to use this mechanism in your own apps:
https://github.com/jensmeder/DarkLightning
https://github.com/rsms/peertalk
This mechanism is App Store compliant in case u need to publish your app later. One popular example is an app called Duet Display that allows you to use your iPad as a second screen via USB.
Hope that helps.

ASCII code on an external device through USB port

Is it possible to send an ASCII code on an external device through USB port using IOS API? I assume that it is possible through bluetooth connection, but I'm not sure through USB connector. Any thoughts?
I would appreciate if someone could put me in the right direction.
Thanking you in advance
That largely depends on the level of sophistication of this "external device". If this external device is just a bare metal embedded device without some sort of operating system you definitely need MFI.
Otherwise, you can run a usbmuxd server (e.g. on Raspberry PI with Linux) to establish a connection via USB. Usbmuxd is basically the technology that Apple uses to communicate between iOS devices and Desktop apps such as iTunes or Xcode. And yes, it is App Store compliant, e.g., Duet Display uses this approach to make an iPad a secondary display for your Desktop via USB.
There are several open source libraries that provide a high level API, e.g., PeerTalk or DarkLightning.

Ios filesharing without iTunes or an internet connection

I am working on developing an enterprise application for ios 7 that needs to work offline and then sync with a desktop client (that I also need to write) for data transfer.
My company does not allow wireless or cell data in this area, and would strongly prefer to not use iTunes either.
The question is, how do you transfer data from an iPad over the usb cable to a custom windows program, without iTunes.
The simplest answer would be: iExplorer (http://www.macroplant.com/iexplorer/) plus some kind of a script to automate the data sync.
Otherwise, you can use the ExternalAccessory framework to communicate with the desktop via a USB tether. This would necessitate a desktop client running simultaneously to communicate with the device.
peertalk (https://github.com/rsms/peertalk) does what you want, however the computer side library is only for mac os. Maybe you can port the protocol to windows by looking at that (the license is BSD)
Edit: this guy managed to have it run under linux. It sits on usbmuxd, which also has a windows port, so it shouldn't be impossible.

iOS socket list of hosts wlan

I have some WLAN-Device, that I communicate with.
At first I go to IOS Settings and connect to the device directly.
Then in my App I need to input the ip and port to open a socket.
Until now I knew the IP and Port, to open a socket connection to this device.
But if I am already connected (Adhoc) to the device, why I can not find this stuff automatically?
I already saw some solutions, but most of them need the usage of dynamic libs or just not longer available in iOS7.1. I can not use dynamic libs, because this App should go to AppStore.
There is no other way since iOS 6.
You have to scan the location. "Reachability" could help you, if you know the name of the host. Also you could try to scan the posible IP's. With Thread limited by 5 Operations it could go preaty fast.

Resources