Which USB spec actually defines support for Dual Role Device? Type-C or USB 3.1?
Dual-role USB ports were introduced in so-called &quot;On-The-Go&quot; (OTG) supplement to USB specifications. (still cannot figure out what OTG means). The role swap came at the expense of introducing one extra pin - ID pin. Therefore originally only mini- and micro-USB ports can provide the swap function, and Type-A can't provide the swap. Additional function of source-sink swap  was provided at DC level, called &quot;accessory charging&quot;.
Type-C Cable and Connector Specification is the next step in providing flexibility to USB. Type-C specifies new CONNECTOR, which can carry various data protocols, although originally it was supposed to be only USB. Thus the Type-C is the standart nearly independent from USB (or anything else), and USB2, 3.x or 4 don't matter.
Keep in mind that there are two basic roles of a port - power role, and data role. Since USB is a host-centric protocol, this distinction is quite important. So four combination of roles are possible. Type-C basic (DC-based) communication functionality (over CC pulls up-down) defines only the default swap function - either a host (and a power source), or a device (and a power sink). To provide two other configurations (host-sink and device-source), a negotiation over additional protocol is required. It is implemented within Power Delivery protocol over the same CC wire using serial communication messages.