Is it possible to listen to device connections via libimobiledevice? - libimobiledevice

I am trying to do something every time my iPhone is connected (via USB or wifi). Current alternative is polling list_devices and wait to see my device listed.
Is there something better or polling is the only option?
This is platform independent, but I am testing on Windows

You can subscribe for notifications which are sent by iTunes/usbmuxd whenever a new device is connected. If you're using libimobiledevice, you can use idevice_event_subscribe to register a callback which is invoked whenever a device is added or removed.


AWS IoT Jobs and OTA Updates when device is in sleep mode

What happens if I send an OTA Update and the device is in deep sleep mode? It wakes up immediately, waits for the next wake up and then runs automatically or it does not run at all on it?
Depends a lot on what your device is, how "deep sleep" and wakeup from it is implemented in this device and how it's connected to Internet.
Option 1: no. Most likely the networking hardware is switched off to save power and (if it's really deep sleep) the micro's core is also suspended (i.e. it doesn't execute code). In this state the device couldn't receive any messages from the network.
Option 2: depends on what the device does when it wakes up. If it connects to Internet and connects to AWS IoT and receives the command, then probably yes. This functionality is up to the developer of embedded firmware to design and implement. Otherwise no.

C program stalls when the serial device's path changes

In Linux I am running in the background a program written in C, which periodically communicates with a device connected to one of the USB ports. Although the device is always plugged into the same port, over time it switches from /dev/ttyACM0 to /dev/ttyACM1 and back, even when no other devices are connected. Consequently every time a switch occurs, I have to restart the program.
To cope with the problem I have tried setting up a UDEV rule for a new symlink and the the symlink works regardless of the changes in the connected device's path. However, when the switch occurs, the program still stalls and needs to be restarted.
Is there a system rule I can implement for the device to keep the same path at all times, or is there another more general approach?
First approach (easier):
If you have access to the other's device code, I would implement a ping message from it.
Then, I would listen for that ping message, on both tty devices, to see on which port it is received (/dev/ttyACM0 or /dev/ttyACM1).
Second approach:
On a separate thread implement an UDEV monitor.
The monitor checks which TTY port is used by your device.
In case of a port change, just reinit the communication thread...
See udev_monitor_usb.c for a udev monitor usb code.

Driver to User-Mode Communication

I am trying to write a tool to monitor processes. Whenever a high privileged process with SYSTEM privileges is created it will alert the user.
I'm doing this with a driver that monitors every process creation and a user mode app to check if it runs under SYSTEM and if so to make the alert.
For doing this the user-mode app should listen to the driver. I'm trying to do it with event. Whenever a process is created the driver will signal the event with IoCreateNotificationEvent (which the use-mode app listens to with WaitForSingleObject) and then the app will send an IRP to the driver to get the pid.
That doesn't work well for me and I was looking for other methods to do that communication from the driver to a listening user-mode app and I couldn't find so..
How can I make it work?
Thanks for helping
The usual method would be to use an asynchronous IOCTL, forget the event entirely, just have the driver save the IOCTL if there is no outstanding process creation to read and then complete the IOCTL when you get a new process. This does require that the client submit the IOCTL requests ahead of process creation. For best results I would say bind your device handle to an IOCP (I find IOCP far easier to deal with than needing to track which event goes with which OVERLAPPED).
Another way to communicate from Driver to User mode process is for the user mode process to open a pipe in message mode and listen to messages from kernel. It is simpler than implementing asynchronous IOCTL as you do not have to deal with pending IOCTL that may need to be cancelled. Make sure that when you open the pipe, it is ACL'd correctly so that only the kernel can talk to the pipe opened by the user mode process.

windows: how to stop irda dongle periodic auto detecting

I'm writing some code in C for an IrDA project on one win7 32bit computer. I have another computer setup to display any data received via in infrared. This part works. However the as soon as I connect the IrDA dongle to the PC, it starts to send periodic data for searching other IrDA devices. I want to disable this behavior programmatically so I see only the data sends as a result of my code. Anyone know which command to use? Is it WSASetService? I didn't learn socket programming, not sure what "removes from the registry a service instance within one or more namespaces. " really means.
Have you disabled the Infrared Monitor Service manually?
I experienced problems with this functionality in win7 when using Windows to communicating with an embedded micro-controller based device that worked well with windows XP.
I disabled the Infrared Monitor Service manually and found that windows was still polling the IrDA periodically!
I have not found any documentation available that describes it or how to disable it, I will continue searching...

How can I capture the key pressing from a external equipment?

I have a hardware which connect with my computer via com interface, I want to implement such a feature:
When the button on the hardware is clicked, My application can capture this event and then write something on my application.
So How can I listen to a specific COM interface and capture the event ?
How can I get what command the hardware sent to me ?
You're looking for the System.IO.SerialPort class. It will allow you to open a serial port (a COM port) and read and write data. As for the specifics about how to capture a button press, that would depend entirely on the device. If you know that it sends data over the COM port when a button is pressed, then you just need to know what to expect and you'll be able to capture it.