Showing posts with label P2P. Show all posts
Showing posts with label P2P. Show all posts

Monday, 5 August 2013

Part 3: P2P Group Owner Negotiation


Once the two P2P Devices have found each other, they start the Group Owner(GO) Negotiation phase. This is implemented using a three-way handshake, namely GO negotiation.Request/Response/Confirmation,  whereby the two devices agree on which device will act as P2P GO and on the channel where the group will operate, which can be in the 2.4 Ghz or 5 Ghz bands.

In order to agree on the device that will act as P2P GO, P2P devices send a numerical parameter, the GO Intent value, within the three-way hand-shake, and the device declaring the highest value becomes the P2P GO. To prevent conflicts when two devices declare the same GO Intent, a tie-breaker bit is included in the GO Negotiation Request, which is randomly set every time a GO Negotiation Request is sent.


P2P GO Negotiation Request from device 1:



If operating channel is not available, it will use another channel from the Channel List.Configuration time is Time needed by the device to get configured an function as a GO in units of 10 milliseconds.

 WPS IE in GO negotiation request:

GO negotiation response from device 2:



WPS IE in GO negotiation response:

                

When using PIN based WSC, the selected PIN (from the display of either the
P2P Client or P2P Group Owner) is indicated using Device Password ID
attribute. For example for devices using pushbutton authentication,


A P2P Device may decline Group Owner Negotiation if the Device Password ID
in the GO Negotiation Response is incompatible with the Provisioning
information it shall use to execute Provisioning.

P2P GO Negotiation confirmation from device 1:


Group Owner determination is depicted below.


Once the devices have discovered each other and agreed on the respective roles, the next phase is the establishment of a secure communication using Wi-Fi Protected Setup.

Thursday, 25 July 2013

Part 2: P2P states

Run wpa_supplicant and wpa_cli in STA1 in another terminal.Similarly run wpa_supplicant and wpa_cli in STA2 also. (please refer to this link )

To discover other P2P devices, use p2p_find command.


Now, state machine enters scan and find phase. (find phase alternates between listen and search state.)




Scan phase

In scan phase all supported channels are scanned. It can either be an active scan or a passive scan. It sends probe requests in channel 1 to 11 or listens to beacon from channel 1 to 11.


Find phase:

1. Listen state

A P2P device that is not in a P2P group may use listen state to become discoverable.

  • In listen state P2P device dwells on listen channel (configured in p2p.conf => p2p_listen_channel=1 to configure listen channel as 1) for at least a contiguous period of 500ms every 5 seconds.
  •  Listens for probe requests and shall only respond to probe requests that contain P2P IE.
  • If probe request contains WPS IE with device type attribute, it  shall only respond if device type is same as it's primary and secondary device type.
Duration of each listen state shall be a random number 'T' such that,
Max discoverable Interval value > T > Min discoverable Interval value

Following is a P2P IE in probe request frame:


Group Limit field is 0 indicates that additional P2P connections are supported.
1 indicates that no further connections are allowed.

WPS IE in the same probe request:


2. Search State:

Alternates between channels 1,6 and 11. Sends probe request in one channel and listens for probe response from the same channel.

Find state is a combination of listen and search states.






Wednesday, 24 July 2013

Part 1: P2P aka WiFi Direct - Introduction and Configuration of wpa_supplicant in Linux kernel version 3.8.3

What is P2P?

P2P alias Wi-Fi Direct builds upon the successful IEEE802.11 infrastructure mode and lets devices negotiate who will take over the AP-like functionalities. Thus, legacy Wi-Fi devices may seamlessly connect to Wi-Fi Direct devices . By taking this decision, Wi-Fi Direct immediately inherits all the enhanced QoS, power saving, and security mechanisms.


In a typical Wi-Fi network, clients discover and associate to WLANs, which are created and announced by Access Points (APs). In this way, a device unambiguously behaves either as an AP or as a client, each of these roles involving a different set of functionality. A major novelty of Wi-Fi Direct is that these roles are specified as dynamic, and hence a Wi-Fi Direct device has to implement both the role of a client and the role of an AP.


The device implementing AP-like functionality in the P2P Group is referred to as the P2P Group Owner (P2P GO), and devices acting as clients are known as P2P
Clients.Legacy clients can also communicate with the P2P GO, as long as they are not 802.11b-only devices and support the required security mechanisms.

For example, consider a laptop accessing the Internet through a legacy infrastructure AP while at the same time streaming content to a TV set by establishing a P2P Group, where the laptop acts as P2P GO.If the P2P GO leaves the P2P Group then the group is torn down, and has to be re-established using some of the specified procedures.

Wi-Fi Direct devices usually start by performing a traditional Wi-Fi scan (active or passive), by means of which they can discover existent P2P Groups and Wi-Fi networks.

After this scan, a new Discovery algorithm is executed, which we describe next. First, a P2P Device selects one of the so-called Social channels, namely channels 1, 6 or 11 in the 2.4 Ghz band, as its Listen channel.

Then, it alternates between two states: a search state, in which the device performs active scanning by sending Probe Requests in each of the social channels; and a listen state, in which the device listens for Probe Requests in its listen channel to respond with Probe Responses. The amount of time that a P2P Device spends on each state is randomly distributed, typically between 100 ms and 300 ms.


How to know if your device supports p2p? Use iw list command in terminal and look for the following field. If it contains p2p-client and p2p-GO, you can be assured that your device supports P2P.



Just like a client and server model, you need to run supplicant and p2p client.
Supplicant is a daemon running in the user space to provide authentication.

mac80211 and cfg80211 does not implement WPA feature. So you need a seperate program which provides supplicant functionality in Linux which is
wpa_supplicant.Install latest release of wpa_supplicant from http://hostap.epitest.fi/releases

I downloaded: wpa_supplicant-2.0.tar.gz


First thing you need to do is to create the .config file in the folder wpa_supplicant-2.0/wpa_supplicant from defconfig file.


Enable following options in defconfig file (uncommenting is removing # in defconfig file)


CONFIG_CTRL_IFACE=y
CONFIG_DRIVER_NL80211=y 
CONFIG_WPS=y
CONFIG_WPS2=y
CONFIG_P2P=y
CONFIG_AP=y

Give cp defconfig .config command and then make command in wpa_supplicant 
folder. Now there are two binaries created wpa_supplicant and wpa_cli. In order to run wpa_supplicant we need a config file. Traditionally it is created in /etc folder. Here is a sample config file for p2p. (/etc/p2p.conf)
ctrl_interface=/var/run/wpa_supplicant
update_config=1
device_name=PRIYA-P2P
device_type=2-0050F204-1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1
p2p_go_intent=1
p2p_no_group_iface=1



Find out the wireless interface using iwconfig command and then give the following command in wpa_supplicant

./wpa_supplicant -i wlan2 -c /etc/p2p.conf -Dnl80211

You will see a msg "Successfully initialized wpa_supplicant" which means that supplicant has started running.In another window run the wpa client using ./wpa_cli

This opens an interactive mode in which commands can be given.
Interactive mode
>


(Tip: Use killall wpa_supplicant if you get error message like: 

ctrl_iface exists and seems to be in use - cannot override it Delete '/var/run/wpa_supplicant/wlan2' manually if it is not used anymore Failed to initialize control interface '/var/run/wpa_supplicant'. You may have another wpa_supplicant process already running or the file was left by an unclean termination of wpa_supplicant in which case you will need to manually remove this file before starting wpa_supplicant again.  )