How to Setup Wi-Fi Direct on Android/Ubuntu Terminal

How to Setup Wi-Fi Direct on Android/Ubuntu Terminal – Part1 | அருண் வலைப்பூ - Arun's Blog

What is Wi-Fi Direct ?

Wi-Fi Direct nothing but Wi-Fi Peer-to-Peer[P2P] Communication without using wireless AP[Access Point]. Wi-Fi Direct standard Developed by Wi-Fi Alliance group and it act as a “Soft AP” with WPA2-PSK security features.

What are all software required for Wi-Fi P2P operations ??

  1. wi-fi NIC Driver – kernel driver module
  2. cfg80211 –> 80211 configuration
  3. iw – wireless Tool for configuration
  4. libnl – Network Link Library
  5. wpa_supplicant –> Manages P2P operations at user-space
  6. wpa_cli  – client tool to interact with wpa_supplicant in daemon mode.

On Android  from ICS – wpa_supplicant V0.8.x supports Wi-Fi Direct.

  • You need to install libnl and openssl libraries for wpa_supplicant

On Ubuntu – wpa_supplicant V1.1 supports Wi-Fi Direct.

  • You need to install libnl and openssl libraries for wpa_supplicant

Install Required Software’s

iw and wpa_supplicant userspace command line tools are required in-order to perform wi-fi Direct / p2p operations on Ubuntu Linux.

iw:

sudo apt-get update &&  sudo apt-get install iw

wpa_supplicant version 1.x:

sudo apt-get install wpa-supplicant or

#for Latest Ubuntu

sudo apt-get install wpasupplicant

Wireless Adapter Supports Wi-Fi Direct

To verify the p2p Group/Client support for your Wireless Adapter use iw command as a sudo/root

$ sudo iw list

Grep and check for following block to see the supported modes for your wi-fi adapter.

Supported interface modes:

  • IBSS
  • * managed
  • * monitor
  • * AP
  • * P2P-GO
  • * P2P-Client

If you see P2P-GO(Group Owner) and P2P-Client, then your wireless NIC supports Wi-Fi Direct.

P2P Commands

The following commands are used with wpa_cli.

  1. p2p_find
  2. p2p_stop_find
  3. p2p_connect
  4. p2p_invite
  5. p2p_group_add
  6. p2p_remove_group
  7. terminate
  8. status

For full list of commands please check this post: wpa_supplicant and wpa_cli

wpa_cli commands will used with wpa_supplicant daemon for wi-fi Direct connection establishments.

Wi-Fi Direct Connection Methods

In-order to establish the connection there are different types of connection methods, they are

  1. PBC – Push Button Control method
  2. PIN – Secret PIN number method
  3. Invite – Invitation Method

Please read my previous posts for the basic knowledge about wi-fi direct and wpa_supplicant. Here my previous posts.

General wpa_supplicant.conf – P2P Configuration

  ctrl_interface=/var/run/wpa_supplicant
# For Android Terminals un-comment below line & comment above Line
#ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi

ap_scan=1
device_name=Terminal-1
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1

# If you need to modify the group owner intent, 0-15, the higher
# number indicates preference to become the GO. You can also set
# this on p2p_connect commands.
#p2p_go_intent=15

# optional, can be useful for monitoring, forces
# wpa_supplicant to use only channel 1 rather than
# 1, 6 and 11:
#p2p_listen_reg_class=81
#p2p_listen_channel=1
#p2p_oper_reg_class=81
#p2p_oper_channel=1

 Note: Terminal1-1/Terminal1-1 means Personal Computer or Android Phones/Tablets(rooted).

Terminal-1: sudo vi /etc/wpa_supplicant-t1.conf

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
device_name=Terminal-1
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1

Terminal-2: sudo vi /etc/wpa_supplicant-t2.conf

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
device_name=Terminal-2
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1

Terminal-1: run wpa_supplicant as daemon

sudo ./wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant-t1.conf -Bd

Terminal-2: run wpa_supplicant as daemon

$ sudo ./wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant-t2.conf -Bd

Terminal-1: wpa_cli – client

$ sudo ./wpa_cli -i wlan0

 > #here you can use p2p commands as mentioned below

>

Terminal-2: wpa_cli – client

$ sudo ./wpa_cli -i wlan0

 > # here you can use p2p commands as mentioned below on each terminals

>

1. PBC Method

Terminal-1:

  > p2p_find

Terminal-2:

 >p2p_find

 >p2p_peers

 <Terminal-1 Mac Address>

Terminal-1:

> p2p_peers

<Terminal-2 MAC Address>

Terminal-2:

 > p2p_find

 > p2p_peers

 <Terminal-1 MAC Address>

Terminal-1:

> p2p_connect pbc auth go_intent=7 freq=2412  #channel-1

  • Here GO_INTENT value is very important. Because it decides P2P-GO negotiation.
  • Who is having higher GO_INTENT will be come P2P-GO, the lowest one will become P2P-Client.
  • GO_INTENT values ranges from 0 to 15
  • You can choose any channel by changing the frequency to 2.4GHz/5GHz bands..

Terminal-2:

 > p2p_connect <Terminal-1 MAC Address> pbc freq=2412 go_intent=7

 > status # This will print the connection status

  • Here tie-breaker bit will be set, since the GO_INTENT values are same. Either Terminal-1 or Terminal-2 will become P2P-GO(SoftAP), other terminal will act as P2P-Client.
  • New P2P interface will be created, you can check using ifconfig. i.e. p2p-wlan0

Terminal-1:

$ sudo ifconfig p2p-wlan0 192.168.2.1 up #P2P-GO

$ sudo iw dev wlan0

$ sudo iw dev p2p-wlan0

Terminal-2:

$ sudo ifconfig p2p-wlan0 192.168.2.2 up #P2P-Client

$ sudo iw dev wlan0

$ sudo iw dev p2p-wlan0 link #p2p-wlan0 will keep changing.

Ping Test

Terminal-1:

$ ping 192.168.2.2

Terminal-2:

$ ping 192.168.2.1

Other methods connections, we will continue in my next article.

References:

iw : en:users:documentation:iw [Linux Wireless]
p2p : en:developers:p2p [Linux Wireless]
p2p-readme : http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap-1.git;a=blob;f=wpa_supplicant/README-P2P;hb=HEAD

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值