3

I went through The best way to do TCP/IP over USB on Linux?, and would like to know more about the feasibility/procedure in order to have two Linux boxes IP-talking to each other over USB. I did it few years ago easily over Serial Link and it was quite stable and mature.

The idea is to have the related named network device (eth0, usb0, wlan0, ..) in /sys/class/net and then be able to play around with ifconfig/route commands, just like any other network device for IP address assigning, routing, pinging,... but that's the easy final part.

In order to achieve this, I see different issues/steps:

  1. HW: cabling. I guess 2 computers only have 'host' USB type-A connectors, while usual USB cable have one Type-A and one Type-B connector: a cable should be carefully prepared in order to prevent power being exchanged, but allow only data. Correct? (I am only covering USB <=2.0 protocol here, as I know USB 3.x could perform full-duplex wiring)

    Of course, if I want to connect a PC (host/USB) to a 'device' (rasbpi, mini2440, arduino, ..,) I would actually have a Type-B end and a 'stupid' USB cable could be used. Correct?

  2. Kernel/Driver: what is present in the kernel in order to assign a network device to a USB port? Similar to IP over /dev/ttySxx? What if the USB kernel driver is not ready on the other side?

  3. Identification of port/connector: how shall the kernel know which port I am actually using (especially if power wiring is cut-off on dedicated cable)? How do I identify my port?

  4. Finally, from a network layer point of view, what should I expect? a simple bridge for Ethernet? or each USB side would have an assigned IP address?

I hope this is not too confused, and you get what I am trying to achieve. But since it use to be so simple to do IP (Ethernet?) over a serial link, I hope it is also the case for USB.

  • I've wondered about a modern equivalent to the nullmodem cable I used to play Command&Conquer over back in the day. Outside of a crossover Cat5 cable, of course. Upvoting for interest. – Jarmund Jul 1 '16 at 13:43
  • Oucch! Makes me think that I should mention I wouldn't use anything 'intelligent' between the 2 PCs but a double A-Type connectors cable. – bli Jul 4 '16 at 12:51
0

1) The problem with usb is it is a master/slave protocol. PCs are masters, and you cannot connect two masters directly together so a direct dumb cable will not work.

You can use something like https://www.amazon.co.uk/Ethernet-Network-Adapter-Converter-Connection/dp/B003Q85EEA but then you may as well just use ethernet. Any other hardware solution is going to be similar:

pc <--usb--> usb slave ic/microcontroller <--common protocol--> usb slave ic/microcontroller <--usb--> pc

2) For something like the usb network adaptor above it should already have a kernel driver which will set up an network device for you which you can interact with the same way you do with eth0 or wlan0 but might have a different name.

A properly designed ic (like the one in the device mentioned above) that works with the inbuilt kernel module will not care if the device on the other end is ready, it will just be like the ethernet cable is unplugged.

3) The device should be exposed like any other network adaptor, ip addr or ifconfig should list it once connected.

4) You should expect a network device like any other device, you can treat it like a ethernet cable directly from one computer to another.

You cannot use a raspberry pi for this, it is a host device like the pcs.

Arduino could work, but you will require two. The leonardo is better is it has built in usb support so will give you better speed. But the arduino has no software to support usb networking so you will have to write this yourself (not trivial). The same is going to be true for a lot of microcontrollers. Best bet is finding one with slave networking support, I think the mbed can do this but you will still need to write code to bridge the two microcontrollers.

But the easyist/cheapest way is to use two of something like https://www.amazon.co.uk/Ethernet-Network-Adapter-Converter-Connection/dp/B003Q85EEA. Then remove the casing, de-solder the headers and solder a ethernet cable directly to the ports. But that won't give much advantage over just using an ethernet cable, if anything will make it a slightly less flexible solution (though maybe less bulky). You could create your own board with the ICs on and bridge them on a single pcb but this will be quite a bit more work for no real benefit.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.