Mac - virtual serial port

I need to create a Cocoa application that will create a virtual serial port accessible by other applications, i.e. registered in the IO Kit registry.

The essence of the application:

  • Create a virtual serial port (specified in / dev and registered in the IOKit registry)
  • Initiate a tcp connection to another computer.
  • A proxy server received by the entire virtual serial port of the network and vice versa.

This application will be used by third-party applications that will talk to serial ports on the computer, allowing you to locate a specific serial device over the network. Cocoa and the network part is not a problem, I wrote several applications that speak over the network. My hang is a serial port.

I ran a test using socat / netcat / minicom to make sure that all this works with the pty / tty proxy over the network, but the tty that I use does not appear to be suitable for use by random applications, because it is not registered in IO Kit Registry.

While I can use master / slave pty / tty for communication, I need this slave tty to display Mac applications. Which would be very convenient is a way to register tty in the IO Kit registry.

Do I really need to create a custom IOKit kext driver that registers in Cocoa application runtime? If so, I have a big learning curve ahead. Where should I start reading? Or can I use IOKit to create a virtual serial port and register it as a convenient serial port for applications without having to download any kernel extensions?

Thanks for any help you can provide.
Stateful

+4
source share
2 answers

First of all, you checked if you can make a decision from this application? This is not obvious from the site if they managed to ensure that their virtual serial ports are fully integrated into the system.

If there is a way to do this from user space, I don't know about that. The IOKit API for user space usually does not allow class instances, not to mention the new device driver classes. Perhaps you can somehow convince Cocoa libraries to find it even though it is not registered in the kernel.

I don’t know if you can get away with creating the "dummy" serial port in the kernel, and then move your tty to its place in / dev from your user space demonstrator. Perhaps this is an option.

If you need to do all this in the kernel:

The virtual driver itself should not work too much, although it will take some time to speed up work with the dev kernel. Unfortunately, the documentation is pretty thin for serial port drivers - the key subclasses the abstract class IOSerialDriverSync . Almost the only description I've seen is Ole Henry Halvorsen OSX and iOS Kernel. It also has an example snippet for read and write operations. ( disclosure: I was one of the reviewer technicians for this book, I get no incentive to recommend - in this case, this is literally the only documentation I know of). You can find the source for the full serial port driver in the Apple USBCDC driver , AppleUSBCDCDMM is the class that actually represents the node serial port.

It is relatively simple to open the so-called “control core” in the kernel, the individual APIs described here ; from user space, you use the usual send / recv BSD APIs. (this is also described in the aforementioned book). Then your daemon can connect to this, and all you have to do is push the data between the socket and the virtual serial port device. You will need to handle disconnect events and, of course, correctly.

However, I think this is possible as the first kernel project for an experienced C programmer (with some C ++).

I hope this helps!

+4
source

You can take a look at these libraries on Github:

ORSSerialPort

OSX-speed-serial

and this website:

Mac USB Serial Com

0
source

Source: https://habr.com/ru/post/890361/


All Articles