7

USB has always made a distinction between the "host" and "peripheral" roles that a device can operate in: there's a single "host" (such as a PC) that manages the bus, and there can be many connected "peripherals" that communicate with the host. You can't connect a host to a host, nor a peripheral to a peripheral. This distinction has historically been enforced by the connectors: hosts have type-A sockets, and peripherals have type-A plugs or type-B sockets.

USB-C, however, uses the same connector for both hosts and peripherals. This makes me wonder what determines which one will be the host. Does a USB-C cable have a "host end" and "peripheral end" that can be distinguished electrically even though they look the same? Do the devices negotiate which will be the host? If so, what criteria do they use?

On a related note, USB hosts have historically provided power to peripherals, both to let them operate (e.g. USB mice and flash drives) and to charge their batteries (e.g. phones). With the type-A and type-B connections, it was always clear which device would charge which. With type-C, it's not so clear.

My phone (Nexus 5X) and tablet (Pixel C) both have USB-C ports, and I've found that if I connect them together with a USB-C cable, the tablet always charges the phone by default, no matter which way I connect the cable. But if I connect them with a USB-C OTG adapter and an A-to-C cable, the device connected to the adapter is always the one that provides power, which can result in the phone charging the tablet. So it seems that there's a mandatory charging direction when a USB-A port is involved, but with a native USB-C connection the devices can somehow figure out the "right" direction for power to flow. How do they determine that? What would happen if I connected two identical phones together, or two laptops with USB-C ports?

Since there are a bunch of little questions above, here's the big over-arching one: some elements of a USB connection must be directional (host vs. peripheral, and charging direction), so how does a USB-C connection determine which one is which?

3
  • Related: electronics.stackexchange.com/questions/255684/…
    – 2xsaiko
    Apr 15, 2017 at 19:28
  • This should be closed in favor of that electronics SE one.
    – chx
    Apr 17, 2017 at 20:51
  • “so how does a USB-C connection determine which one is which?” – Exactly the same way any other USB connection does it: Not at all. Basic USB-C cables are as dumb as any other USB cable that came before. The different USB-A/B plugs are just for humans. They have no electronic meaning whatsoever.
    – Daniel B
    Nov 5, 2021 at 10:13

2 Answers 2

3

Since this wasn't closed I will answer it here.

In USB C the roles a device can play is separate data and power wise. These are all negotiated by sending data packets over the configuration channel - USB C has a separate CC wire for this which is missing from legacy A/B connectors. This is all prescribed in the USB Power Delivery standard. (While the USB Type-C standard uses the USB PD protocol, USB PD could, in theory, be used elsewhere.)

Power roles can be

  1. provider also called source
  2. consumer also called sink.
  3. dual role power (DRP) port.

For data

  1. No data
  2. downstream facing port (DFP) -- this means it sends the data.
  3. upstream facing port (UFP) this means the device receives the data. A monitor or a mouse is an example.
  4. dual role data port (DRD). The port’s power role at attach determines its initial role. A source port takes on the data role of a DFP, while the sink port takes on the data role of a UFP. If a port is both DRP and DRD connecting them together will randomly lock one to source and DFP and the other to sink and UFP. Once this initial connection is done, role swaps can be negotiated as needed.

As we know, USB C is very flexible (in less charitable terms: it's a gigantic mess) and it's very hard to give good examples in the list above. For example, USB C ports on a portable monitor might be:

  1. A power sink with no data roles -- this might serve the purpose of powering the monitor from a USB C charger while the video is provided over say HDMI or even from a laptop on another USB C port which can't provide adequate wattage.
  2. An UFP for video and potentially data. ​This will likely be a power sink.
  3. If it has a built in battery it might be an UFP and a power source to charge the device it gets the video from. It is also possible there's a menu option to switch between source and sink roles so either a laptop can charge the monitor or the monitor can charge the laptop.
  4. Again, if there is a battery inside, it might serve as a docking station too so it can provide a port which is DFP and power source.
  5. Instead of the battery inside the monitor, it might ship with a battery bank crossed with a docking station and for that it might provide a DFP which is a power sink.

As for the example in the question, if you have an adapter which provides a USB A receptacle and it is up to standard it will sport a USB C male connector on the other end. Plugging the USB C end into a device will force the device to assume a DFP role and it will also provide 5V to the legacy USB device connected. This is neither source or sink, it's a legacy mode. Instead of nice negotiation, it's forced via some resistors. BTW there's no such thing as "USB C OTG", that's marketing term.

1

You can't connect a host to a host

Actually you can, this has been part of the USB 3.0 spec when it was released in 2010. This requires a special cable if using USB-A to USB-A but if one or both hosts have USB-C then a common cable like that used to connect a hard drive or smartphone will work. Depending on the smartphone it may in fact be using host-to-host communications without the user knowing.

Connecting Windows or Linux hosts to each other by USB is supported on most any system with USB-C but it's not easy to setup, and even then unless or until someone writes some more software for this communication the utility is quite limited. Apple hardware supports USB 3.x host-to-host communication as well but most people will find it much easier to use Thunderbolt instead, it's faster, the operating system supports this function, and in the case of USB-C it uses the same port as USB 3.x. Thunderbolt has stricter cable requirements for host-to-host communications, some USB 3.x cables work for Thunderbolt, some don't.

I do wish that someone would bring USB host-to-host communications to the novice users, so many people ask for it. This is a software problem, all the hardware is there with perhaps some exceptions on early implementation of USB-C.

This distinction has historically been enforced by the connectors: hosts have type-A sockets, and peripherals have type-A plugs or type-B sockets.

USB-C, however, uses the same connector for both hosts and peripherals.

The "A type" and "B type" ports are not lost with USB-C, it's just not enforced with a physical connector any more. Enforcement is done electronically.

This makes me wonder what determines which one will be the host. Does a USB-C cable have a "host end" and "peripheral end" that can be distinguished electrically even though they look the same? Do the devices negotiate which will be the host? If so, what criteria do they use?

A USB cable with USB-C connectors on both ends will not have a host (or A type) and peripheral (B type) ends. The way the connectors work though someone could construct such a cable, but that would violate the USB specifications on how such cables are to be wired. I've seen non-compliant USB-C cables before and when constructed with care and a purpose they can be quite useful, the problem is that the cable would have to be marked in a way to point out it's unique purpose to avoid confusion and complaints. Making this distinction clear to users could be trivial to near impossible, which is why the people behind USB don't allow such cables to bear their trademarks or claim certification.

When connecting two hosts by USB-C a number of things can happen depending on the capability of the computers. If both computers support dual-role ports then the role each takes is random, and this can result in things like a phone charging a laptop even though that is not what the user wanted. The hosts will have a short memory on which role they had so reversing the role can be done by unplugging and reconnecting. Some people will flip the cable around in the mistaken belief that the cable has some built-in directionality, which is then reinforced by the role reversal. This can be proven false by disconnecting and reconnecting without flipping the cable.

Not all USB hosts have dual-role ports and so if one is host only and the other dual-role then the dual-role host will take on the peripheral role. As you discovered there is nothing interesting happening if two peripheral devices are connected by a USB-C cable.

Connecting two host only computers by USB-C will allow host-to-host communications but only if the correct settings have been made in the operating system. Depending on how the ports are configured there may be a kind of "master" and "slave" role playing but this is on software layer outside of USB-C and USB 3.x. They may take on peer/peer roles on this layer as well.

This is ignoring alternate modes on USB-C such as Thunderbolt, DisplayPort, and more. The way Thunderbolt works there is a peer/peer relationship, and the role of power source or sink is negotiated if needed. Video modes on USB-C, such as DP, HDMI, and MHL, have much simpler role negotiation as data for video, sound, device control, and a few more bits only go one way. When there is a bit of data going the other way, like an audio or Ethernet channel, then it is kept on a set of wires distinct for this purpose.

So it seems that there's a mandatory charging direction when a USB-A port is involved, but with a native USB-C connection the devices can somehow figure out the "right" direction for power to flow. How do they determine that? What would happen if I connected two identical phones together, or two laptops with USB-C ports?

There is a protocol for handling power, and it is called USB-PD. USB-PD is a bidirectional protocol that is independent from the flow of audio, video and other data, a protocol based in large part from older standards of USB-BCS (battery charging system). This is base on the lowest levels of USB power going back to USB 1.0 and 1.1. From that grew USB-BCS, and later USB-PD which are the standards on which others grew. Apple extended some of this to create their AppleID protocol, which works well when USB-BCS fails and USB-PDS is slow, expensive, and taxing.

Since there are a bunch of little questions above, here's the big over-arching one: some elements of a USB connection must be directional (host vs. peripheral, and charging direction), so how does a USB-C connection determine which one is which?

USB-C is a port that can carry multiple independent data paths and each can negotiate which is going where. Power negotiation is relatively simple, a determination of the voltage and direction. This direction of power flow can be dictated by the capability of the host, and can change at any time based on need. The power host and slave have nothing to do with the direction of the data flow. That flow is negotiated independently on each of the four super speed lanes. The protocol can be unique as well. A USB lane will have a matching USB lane. MHL may have a matching lane, three such lanes, or no matching lane and go it allow.

USB4 allows for USB, Thunderbolt, and DisplayPort to share lanes. Each of these Super speed lanes can flow in any direction. That is independent from USB 2.0. Also independent is power flow.

USB, Thunderbolt, and DP can share data lanes but not when MHL or HDMI are around. HDMI demands all super speed lanes. MHL needs it's own lanes, and any not used can be occupied by only USB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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