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. )