Feeds:
Posts
Comments

Archive for March, 2014

 

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

 

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 : http://wireless.kernel.org/en/users/Documentation/iw
p2p : http://wireless.kernel.org/en/developers/p2p
p2p-readme : http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap-1.git;a=blob;f=wpa_supplicant/README-P2P;hb=HEAD

Advertisements

Read Full Post »

கற்க கசடற

 

What is WPA_SUPPLICANT ?

wpa_supplicant is a daemon for wireless connection management on Andorid/Linux OS. You can check your laptop running will be using wpa_supplicant in background.

ps -aef | grep wpa_supplicant

Refer here: wpa_supplicant

 

Download

mkdir -p ~/work; cd ~/work;
wget http://hostap.epitest.fi/releases/wpa_supplicant-2.1.tar.gz
tar  zxvf wpa_supplicant-2.1.tar.gz
cd wpa_supplicant-2.1/
cd wpa_supplicant/
pwd
/home/tulashi/work/wpa_supplicant-2.1/wpa_supplicant

 

Build Environment

Install compilations utilities such as gcc, make etc.

sudo apt-get update

sudo apt-get -y build-dep gcc-4.6 build-essential

 

P2P Configuration

cp defconfig .config
echo “” >> .config
echo “#Arun Kumar: Enabling Modules for Wi-Fi Direct aka P2P” >> .config
echo CONFIG_P2P=y >> .config
echo CONFIG_AP=y >> .config
echo CONFIG_WPS=y >> .config

 

Compilation & Installation

make

You may or may not get errors while compiling the source codes.I have faced following compilation errors and given corresponding solutions for the same as follows

Error#1

#######################################################################
CC  ../src/drivers/driver_wired.c
../src/drivers/driver_nl80211.c:25:31: fatal error: netlink/genl/genl.h: No such file or directory
compilation terminated.
make: *** [../src/drivers/driver_nl80211.o] Error 1
#######################################################################

Solution #1
sudo apt-get -y install libssl-dev libnl-3-dev
echo CFLAGS +=-I/usr/include/libnl3/ >> .config

make

Error#2
../src/drivers/driver_nl80211.c:95:9: warning: passing argument 1 of ‘genl_ctrl_alloc_cache’ from incompatible pointer type [enabled by default]
/usr/include/libnl3/netlink/genl/ctrl.h:25:14: note: expected ‘struct nl_sock *’ but argument is of type ‘struct nl_handle *’
../src/drivers/driver_nl80211.c:95:9: error: too few arguments to function ‘genl_ctrl_alloc_cache’
/usr/include/libnl3/netlink/genl/ctrl.h:25:14: note: declared here

Solution #2

sudo apt-get install libnl-genl-3-dev
echo CONFIG_LIBNL32=y >> .config

make

Now compilation succeeded.

 

wpa_supplicant is really compiled

tulashi@arunx:~/work/wpa_supplicant-2.1/wpa_supplicant$ file wpa_supplicant
wpa_supplicant: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xd69c0b4bbafd67e19dfc86a66bfffdd10c2e2de8, not stripped

 

Running WPA_SUPPLICANT

 

run wpa_supplicant as daemon

 

Run the compiled wpa_supplicant for command lines options as mentioned below

tulashi@arunx:~/work/wpa_supplicant-2.1/wpa_supplicant$ ./wpa_supplicant -h
wpa_supplicant v2.1
Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/)

usage:
wpa_supplicant [-BddhKLqqtvW] [-P] [-g] \
[-G<group>] \
-i<ifname> -c [-C] [-D] [-p<driver_param>] \
[-b<br_ifname>] [-e<entropy file>] \
[-o<override driver>] [-O<override ctrl>] \
[-N -i -c [-C] [-D] \
[-p<driver_param>] [-b<br_ifname>] [-I<config file>] …]

drivers:
nl80211 = Linux nl80211/cfg80211
wext = Linux wireless extensions (generic)
wired = Wired Ethernet driver
options:
-b = optional bridge interface name
-B = run daemon in the background
-c = Configuration file
-C = ctrl_interface parameter (only used if -c is not)
-i = interface name
-I = additional configuration file
-d = increase debugging verbosity (-dd even more)
-D = driver name (can be multiple drivers: nl80211,wext)
-e = entropy file
-g = global ctrl_interface
-G = global ctrl_interface group
-K = include keys (passwords, etc.) in debug output
-t = include timestamp in debug messages
-h = show this help text
-L = show license (BSD)
-o = override driver parameter for new interfaces
-O = override ctrl_interface parameter for new interfaces
-p = driver parameters
-P = PID file
-q = decrease debugging verbosity (-qq even less)
-v = show version
-W = wait for a control interface monitor before starting
-N = start describing new interface
example:
wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf

 

wpa_cli : p2p commands

Wpa_Supplicant needs client to communicate i.e wpa_cli

tulashi@arunx:~/work/wpa_supplicant-2.1/wpa_supplicant$ ./wpa_cli -h
wpa_cli [-pctrl sockets>] [-i] [-hvB] [-a] \
[-P<pid file>] [-g<global ctrl>] [-G<ping interval>]  [command..]
-h = help (show this usage text)
-v = shown version information
-a = run in daemon mode executing the action file based on events from
wpa_supplicant
-B = run a daemon in the background
default path: /var/run/wpa_supplicant
default interface: first interface found in socket path
commands:
status [verbose] = get current WPA/EAPOL/EAP status
ifname = get current interface name
ping = pings wpa_supplicant
relog = re-open log-file (allow rolling logs)
note <text> = add a note to wpa_supplicant debug log
mib = get MIB variables (dot1x, dot11)
help [command] = show usage help
interface [ifname] = show interfaces/select interface
level <debug level> = change debug level
license = show full wpa_cli license
quit = exit wpa_cli
set = set variables (shows list of variables when run without arguments)
get <name> = get information
logon = IEEE 802.1X EAPOL state machine logon
logoff = IEEE 802.1X EAPOL state machine logoff
pmksa = show PMKSA cache
reassociate = force reassociation
preauthenticate = force preauthentication
identity <network id> <identity> = configure identity for an SSID
password <network id> <password> = configure password for an SSID
new_password <network id> <password> = change password for an SSID
pin <network id> <pin> = configure pin for an SSID
otp = configure one-time-password for an SSID
passphrase = configure private key passphrase
for an SSID
sim <network id> <pin> = report SIM operation result
bssid = set preferred BSSID for an SSID
blacklist <BSSID> = add a BSSID to the blacklist
blacklist clear = clear the blacklist
blacklist = display the blacklist
log_level <level> [<timestamp>] = update the log level/timestamp
log_level = display the current log level and log options
list_networks = list configured networks
select_network <network id> = select a network (disable others)
enable_network <network id> = enable a network
disable_network <network id> = disable a network
add_network = add a network
remove_network <network id> = remove a network
set_network <network id> <variable> <value> = set network variables (shows
list of variables when run without arguments)
get_network <network id> <variable> = get network variables
list_creds = list configured credentials
add_cred = add a credential
remove_cred <cred id> = remove a credential
set_cred <cred id> <variable> <value> = set credential variables
save_config = save the current configuration
disconnect = disconnect and wait for reassociate/reconnect command before
connecting
reconnect = like reassociate, but only takes effect if already disconnected
scan = request new BSS scan
scan_results = get latest scan results
bss < | > = get detailed scan result info
get_capability <eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> = get capabilies
reconfigure = force wpa_supplicant to re-read its configuration file
terminate = terminate wpa_supplicant
interface_add <ifname> <confname> <driver> <ctrl_interface> <driver_param>
<bridge_name> = adds new interface, all parameters but <ifname>
are optional
interface_remove <ifname> = removes the interface
interface_list = list available interfaces
ap_scan <value> = set ap_scan parameter
scan_interval <value> = set scan_interval parameter (in seconds)
bss_expire_age = set BSS expiration age parameter
bss_expire_count = set BSS expiration scan count parameter
bss_flush = set BSS flush age (0 by default)
stkstart = request STK negotiation with
ft_ds <addr> = request over-the-DS FT with <addr>
wps_pbc [BSSID] = start Wi-Fi Protected Setup: Push Button Configuration
wps_pin [PIN] = start WPS PIN method (returns PIN, if not hardcoded)
wps_check_pin <PIN> = verify PIN checksum
wps_cancel Cancels the pending WPS operation
wps_reg = start WPS Registrar to configure an AP
wps_ap_pin [params..] = enable/disable AP PIN
wps_er_start [IP address] = start Wi-Fi Protected Setup External Registrar
wps_er_stop = stop Wi-Fi Protected Setup External Registrar
wps_er_pin <UUID> <PIN> = add an Enrollee PIN to External Registrar
wps_er_pbc <UUID> = accept an Enrollee PBC using External Registrar
wps_er_learn <UUID> <PIN> = learn AP configuration
wps_er_set_config <UUID> <network id> = set AP configuration for enrolling
wps_er_config <UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP
ibss_rsn = request RSN authentication with in IBSS
sta <addr> = get information about an associated station (AP)
all_sta = get information about all associated stations (AP)
deauthenticate = deauthenticate a station
disassociate <addr> = disassociate a station
chan_switch <cs_count> [sec_channel_offset=] [center_freq1=] [center_freq2=] [bandwidth=] [blocktx] [ht|vht] = CSA parameters
suspend = notification of suspend/hibernate
resume = notification of resume/thaw
drop_sa = drop SA without deauth/disassoc (test command)
roam = roam to the specified BSS
p2p_find [timeout] [type=*] = find P2P Devices for up-to timeout seconds
p2p_stop_find = stop P2P Devices search
p2p_connect <“pbc”|PIN> [ht40] = connect to a P2P Device
p2p_listen [timeout] = listen for P2P Devices for up-to timeout seconds
p2p_group_remove <ifname> = remove P2P group interface (terminate group if GO)
p2p_group_add [ht40] = add a new P2P group (local end as GO)
p2p_prov_disc <addr> <method> = request provisioning discovery
p2p_get_passphrase = get the passphrase for a group (GO only)
p2p_serv_disc_req <addr> <TLVs> = schedule service discovery request
p2p_serv_disc_cancel_req <id> = cancel pending service discovery request
p2p_serv_disc_resp <freq> <addr> <dialog token> <TLVs> = service discovery response
p2p_service_update = indicate change in local services
p2p_serv_disc_external <external> = set external processing of service discovery
p2p_service_flush = remove all stored service entries
p2p_service_add <bonjour|upnp> <query|version> <response|service> = add a local service
p2p_service_del <bonjour|upnp> <query|version> [|service] = remove a local service
p2p_reject <addr> = reject connection attempts from a specific peer
p2p_invite <cmd> [peer=addr] = invite peer
p2p_peers [discovered] = list known (optionally, only fully discovered) P2P peers
p2p_peer <address> = show information about known P2P peer
p2p_set <field> <value> = set a P2P parameter
p2p_flush = flush P2P state
p2p_cancel = cancel P2P group formation
p2p_unauthorize

= unauthorize a peer

p2p_presence_req [<duration> <interval>] [<duration> <interval>] = request GO presence
p2p_ext_listen [<period> <interval>] = set extended listen timing
p2p_remove_client <address|iface=address> = remove a peer from all groups
sta_autoconnect <0/1> = disable/enable automatic reconnection
tdls_discover = request TDLS discovery with
tdls_setup = request TDLS setup with
tdls_teardown = tear down TDLS with
signal_poll = get signal parameters
pktcnt_poll = get TX/RX packet counters
reauthenticate = trigger IEEE 802.1X/EAPOL reauthentication
raw <params..> = Sent unprocessed command
flush = flush wpa_supplicant state
radio_work = radio_work <show/add/done>

 

ஃ படித்தைமைக்கு மிக்க நன்றி || Thanks for visiting my blog ஃ

Read Full Post »