title: How to set up a Wifi-Direct connection between Android and Linux
body: <p>I want to connect two devices using Wifi-Direct.
  One is a pc with Linux (during my test I'm using Linux Mint 17.2), the other is an Android smartphone (Samsung Galaxy S3 with Android 4.3. Not rooted and don't want to root).</p>
  <p>Reading a number of guides on the internet, I decided to use wpa_supplicant in Linux and to create an app for Android.
  This is one of the best guides I found for wpa_supplicant:
  <a href="https://web.archive.org/web/20210114180304/https://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts" rel="nofollow noreferrer">https://web.archive.org/web/20210114180304/https://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts</a></p>
  <p>When I run iw list I see that the &quot;Supported interface modes:&quot; allows P2P_client and P2P_GO.
  My wpa_supplicant.conf contains:</p>
  <pre><code>ctrl_interface=/var/run/wpa_supplicant
  update_config=1 
  
  ap_scan=1
  device_name=My-pc
  device_type=1-0050F204-1
  driver_param=use_p2p_group_interface=1
  
  p2p_go_intent=15
  p2p_go_ht40=1
  </code></pre>
  <p>The app is very similar to this example (it's from a book) <a href="https://github.com/retomeier/Wrox-ProfessionalAndroid-4E/blob/9741a8b62005d49519b1decfea21e7213fdd94a3/Snippets_ch18/app/src/main/java/com/professionalandroid/apps/myapplication/WiFiDirectActivity.java" rel="nofollow noreferrer">https://github.com/retomeier/Wrox-ProfessionalAndroid-4E/blob/9741a8b62005d49519b1decfea21e7213fdd94a3/Snippets_ch18/app/src/main/java/com/professionalandroid/apps/myapplication/WiFiDirectActivity.java</a></p>
  <p>It works as expected. When I try it with two Android devices, they can see each other and connect (it appear the Wifi-Direct icon).</p>
  <p>Now I am trying to connect Android and Linux, but I guess I don't really understand how wpa_supplicant works.
  I also saw this question that is very similar to what I asked, but it doesn't really answer my doubts...
  <a href="https://stackoverflow.com/questions/17793254/direct-wifi-communication-between-android-smartphone-and-other-devices">Direct Wifi Communication between android smartphone and other devices</a></p>
  <p>My problem is that I can't understand how to do the handshake between the two devices and how to set up the network.</p>
  <p>Wpa_supplicant is my problem. I run:</p>
  <pre><code>sudo wpa_supplicant -wlan0 -Dnl80211 -c/etc/wpa_supplicant.conf
  sudo wpa_cli
  </code></pre>
  <p>But I had a lot of problems:</p>
  <ul>
  <li>The device_name (and other parameters) weren't set as I specifiend in the .conf file</li>
  <li>wpa_supplicant continues to try to connect to all the networks</li>
  <li>p2p_find was really slow...</li>
  </ul>
  <p>so I went into /usr/share/dbus-1/system-services and moved away the two files</p>
  <pre><code>fi.epitest.hostap.WPASupplicant.service
  fi.w1.wpa_supplicant1.service
  </code></pre>
  <p>Now I can</p>
  <pre><code>sudo killall wpa_supplicant
  </code></pre>
  <p>and it really dies, disconnecting me from Wifi without reconnecting the following second.
  Now I can launch wpa_supplicant and the three problems are resolved.</p>
  <p>I go into wpa_cli, launch &quot;p2p_find&quot; and at the same time, I enable the search from within the app.</p>
  <p>Android and Linux can now see each other.</p>
  <pre><code>P2P-DEVICE-FOUND 00:11:22:44:88:ff p2p_dev_addr=00:11:22:44:88:ff
  pri_dev_type=10-0050F204-5 name='GT-I9300' config_methods=0x188
  dev_capab=0x24 group_capab=0x0 vendor_elems=1 new=0
  </code></pre>
  <p>With &quot;p2p_peers&quot; I can see the cellphone MAC.</p>
  <pre><code>&gt; aa:bb:cc:dd:ee:ff
  </code></pre>
  <p>Here I can't go ahead. I tried various possibilities, but none of them worked. My objective is to have Linux as Group Owner.</p>
  <ul>
  <li>Question 1.1: Which is the correct way to handshake the two devices?</li>
  <li>Question 1.2: When I try p2p_connect I often get &quot;Michael MIC failure detected&quot; between the results, what does it means in this contest?</li>
  <li>Question 1.3: Android currently tries to connect with PBC. There is a way to connect with PIN?</li>
  </ul>
  <p>Seeing that I couldn't connect Android/Linux, I tried to do some practice with Linux/Linux (Linux Mint as GO, Ubuntu as Client), following examples from internet like the ones in the first link.
  I have a number of problems even here.</p>
  <p>In Mint I try</p>
  <pre><code>p2p_connect MAC_UBUNTU pin auth
  </code></pre>
  <p>in Ubuntu I try</p>
  <pre><code>p2p_connect MAC_MINT PIN_GENERATED_BY_MINT
  </code></pre>
  <p>When I write the psp_connect in Mint, it creates a new interface p2p_wlan0 _0, and it returns</p>
  <pre><code>P2P-DEVICE-LOST p2p_dev_addr=MAC_UBUNTU
  </code></pre>
  <p>then the p2p_connect launched from Ubuntu fails.</p>
  <ul>
  <li><p>Question 2.1 Why it switches interface when creating the group?</p>
  </li>
  <li><p>Question 2.2 What is the correct way to handle this change? After the change I can't p2p_find Ubuntu anymore (I have to wait some time or restart everything)</p>
  </li>
  <li><p>Question 2.3 Should Ubuntu change it's interface?</p>
  </li>
  <li><p>Question 2.3 In the new interface I should set the IP for both Ubuntu and Mint... how should I do this with static IPs?</p>
  </li>
  <li><p>Question 2.4 If I want to set up for example a DHCP server and client?</p>
  </li>
  <li><p>Question 1.4 And with Android(client) / Linux(GO)?</p>
  </li>
  </ul>