WiFi

 

 

 

WiFi Direct

 

WiFi Direct is a kind of mechanism by which two (or more) WiFi device can talk to each other directly without going through WiFi Access Point. If you are more familiar with how Bluetooth works, you may take 'WiFi Direct' as 'WiFi working like a Bluetooth, but it is much faster since it is communicating over WiFi'.

As of now (May 2015), I saw most of lated mobile phones support this function and you may find a lot of digital TVs and other electronic commodities with labels on it 'WiFi Direct'.

In this page, I will talk about how WiFi Direct works (In 3GPP Rel 12, D2D is proposed for LTE and we may see similar concept in LTE when D2D will be finalized. They would call the LTE version of direct communication as LTE Direct). Overall protocol sequence to establish WiFi Direct connection can be illustrated as below.

WiFi Direct sequence between Device A and Device B: Discovery, Group Owner Negotiation, Switch to AP mode, Attach/Authentication and IP Allocation

  • Discovery : This step is basically same as the discovery process in normal WiFi operation (Refer to WLAN Protocol page for the details). The main difference between WiFi Direct and Normal WiFi operation in this step is that a WiFi Direct Group Owner is transmitting Beacon with an SSID that starts with DIRECT-. Or they can perform discovery via Probe Request/Probe Response.
  • Group Owner Negotiation : Even though 'WiFi Direct' may sound like 'the two device would communicate with equal right', in reality one of the device will be working as Access Point (a kind of Master) and the other device will act as a slave. Group Owner Negotiation is a process to determine who will become the Master and who will become the slave. This step is done three step handshake - GO Negotiation Request, GO Negotiation Response, Go Negotiation Confirmation.
  • Switch to AP mode on Group Owner : Once a Group Owner(GO) is determined, the grouple owner switches its chipset to AP mode (Access Point mode) and start working as a Access Point.
  • Attach Authentication : Now the other device (the device not selected as Group Owner) performs attach process with the GO device. Basically this is similar to normal WiFi operation(Refer to WLAN Protocol page for the details).
  • IP Allocation : At last, GO device allocate IP to Non-GO devices to complete IP layer end-to-end communication path.

In the diagram above, Device A is the device that wins the Group Owner Negotiation, so it is the one that switches to AP mode. The arrows for Discovery, Group Owner Negotiation and Attach/Authentication point both ways, because both devices send frames in those steps. The IP Allocation arrow points only from Device A to Device B, because the GO hands out the address. The sections below open the three steps that the bullets leave short.

How do the devices find each other?

The Discovery step hides a practical problem. Two devices that want to meet must be on the same channel at the same time, but neither device knows the channel of the other. WiFi Direct solves this with a small set of fixed channels and two alternating states.

The fixed channels are called social channels. They are channels 1, 6 and 11 in the 2.4 GHz band, at 2412, 2437 and 2462 MHz. During Device Discovery, a device alternates between two states. In the Search state, it sends Probe Request frames on the social channels. In the Listen state, it stays on one social channel, its Listen channel, and answers Probe Requests with Probe Responses. Each device spends some time in each state. So after a short time, one device searches on the channel where the other one listens, and the two devices find each other.

The Probe Request of Device Discovery carries a P2P information element and the wildcard SSID DIRECT-, so only P2P devices answer it. The Probe Response carries the device information, such as the device name and the WPS configuration methods that the device supports. A device that is already a Group Owner behaves like an AP. It sends Beacons with an SSID that starts with DIRECT- followed by two random characters, and a searching device can also find the group from those Beacons.

  • Social channels are the meeting point : channels 1, 6 and 11 are where P2P devices search and listen.
  • Search and Listen alternate : a device that only searched, or only listened, could miss a peer that does the same.
  • DIRECT- marks WiFi Direct : it is the wildcard SSID in discovery, and the prefix of the SSID of every group.

How is the Group Owner chosen?

The Group Owner Negotiation bullet says that one device becomes the Master. But which one? Each device sends a number that says how much it wants the role, together with one bit for the case of a tie.

The number is the GO Intent, from 0 to 15. A device with intent 15 must become GO. Both values travel in one octet: the intent in the upper 7 bits and the Tie Breaker in bit 0. The requester sets its Tie Breaker, and the responder always sends the opposite value, so the two bits always differ. The decision then follows three rules. First, the device with the higher intent becomes GO. Second, when the intents are equal, the device that sent Tie Breaker = 1 becomes GO. Third, when both devices send intent 15, the negotiation fails, because both devices insist on the role.

Let's check the rules with an example. A phone and a TV both use intent 7. The phone sends the GO Negotiation Request with Tie Breaker = 1, so the TV answers with Tie Breaker = 0. The intents are equal, so the Tie Breaker decides, and the phone becomes GO. The same frames also carry the channel lists of both devices, and the group then operates on a channel that both devices support.

How does a device choose its intent? That is a policy of the implementation. For example, a TV on mains power can use a high intent, because a GO must keep its radio on and send Beacons for the whole group.

  • Higher GO Intent wins : the value range is 0 to 15, and 15 means the device must be GO.
  • The Tie Breaker settles equal intents : the responder inverts the bit of the requester, so exactly one device has Tie Breaker = 1.
  • Intent 15 on both sides fails : two devices that both require the GO role cannot form a group.

How does the client get the key and the IP address?

After the negotiation, the client must join a network that did not exist a moment ago. It has no passphrase for that network. So WiFi Direct borrows WPS to hand over the credentials, and the Attach/Authentication arrow in the diagram above is really two steps.

The first step is WPS provisioning. The devices use one of the WPS configuration methods that they announced during discovery: a PIN shown on one device, a PIN typed on a keypad, a push button on both devices, or NFC. At the end of the WPS exchange, the GO gives the client the credentials of the group, which is a WPA2-Personal passphrase. In the second step, the client connects again with those credentials and runs the normal WPA2 4-way handshake with the GO. From here on, the link works like any WPA2-Personal network, with the GO in the role of the AP.

The last step is IP Allocation. The GO runs a DHCP server, and the client requests an address from it, as it would from a home router. The devices can also store the credentials as a persistent group. The next time, they can then reconnect without a new GO Negotiation and without WPS.

  • WPS delivers the key : the user confirms the connection with a PIN or a push button, and the GO sends the group passphrase.
  • WPA2 protects the link : the 4-way handshake runs as it does with an ordinary AP.
  • The GO is also the DHCP server : the client gets its IP address from the GO, which completes the path in the diagram above.