diff --git a/wpadebug/AndroidManifest.xml b/wpadebug/AndroidManifest.xml
new file mode 100644
index 000000000..95ac7267d
--- /dev/null
+++ b/wpadebug/AndroidManifest.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/wpadebug/README b/wpadebug/README
new file mode 100644
index 000000000..73ebdf32f
--- /dev/null
+++ b/wpadebug/README
@@ -0,0 +1,56 @@
+wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
+Copyright (c) 2013, Jouni Malinen and contributors
+All Rights Reserved.
+
+This program is licensed under the BSD license (the one with
+advertisement clause removed). See the top level README for detailed
+license text.
+
+If you are submitting changes to the project, please see CONTRIBUTIONS
+file for more instructions.
+
+
+NOTE! This Android app is for debugging and testing purposes only. It is
+not supposed to be installed on a production use device and doing so may
+result in complete loss of security protections on the device.
+
+
+
+Build
+-----
+
+- Install Android SDK and build tools
+- update project target if desired; for example:
+ android list targets
+ android update project --target 1 --path $PWD
+- run: ant debug
+
+
+Installation (with adb over USB)
+------------
+
+adb install bin/wpadebug-debug.apk
+
+NOTE: Following steps enable any app on the system to get root access!
+This is not suitable for any production use. This is needed for direct
+wpa_supplicant access and some networking operating in general. You can
+still use rest of the wpadebug app without doing this, but those
+functions will not work unless this step part of installation is
+done. It should be obvious that these steps require a rooted device. In
+addition, if you do not understand what the following commands do,
+please do not run them.
+
+adb root
+adb remount
+adb shell chmod 6755 /system/bin/mksh-su
+
+
+
+Uninstallation
+--------------
+
+adb root
+adb remount
+adb shell rm /system/bin/mksh-su
+
+adb uninstall w1.fi.wpadebug
diff --git a/wpadebug/build.xml b/wpadebug/build.xml
new file mode 100644
index 000000000..5301e69bc
--- /dev/null
+++ b/wpadebug/build.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/wpadebug/project.properties b/wpadebug/project.properties
new file mode 100644
index 000000000..7c6ac0528
--- /dev/null
+++ b/wpadebug/project.properties
@@ -0,0 +1,2 @@
+# Project target.
+target=android-17
diff --git a/wpadebug/res/layout/main.xml b/wpadebug/res/layout/main.xml
new file mode 100644
index 000000000..890d60a79
--- /dev/null
+++ b/wpadebug/res/layout/main.xml
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java b/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
new file mode 100644
index 000000000..19cb14b9b
--- /dev/null
+++ b/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
@@ -0,0 +1,88 @@
+/*
+ * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
+ * Copyright (c) 2013, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+package w1.fi.wpadebug;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.view.MenuItem;
+import android.content.Intent;
+import android.widget.TextView;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+
+public class DisplayMessageActivity extends Activity
+{
+ private static final String TAG = "wpadebug";
+
+ String byteArrayHex(byte[] a) {
+ StringBuilder sb = new StringBuilder();
+ for (byte b: a)
+ sb.append(String.format("%02x", b));
+ return sb.toString();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ Log.d(TAG, "onCreate");
+ super.onCreate(savedInstanceState);
+
+ // Get the message from the intent
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ Log.d(TAG, "onCreate: action=" + action);
+ if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()))
+ return; // handled in onResume()
+
+ String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
+
+ TextView textView = new TextView(this);
+ textView.setText(message);
+ textView.setMovementMethod(new ScrollingMovementMethod());
+ setContentView(textView);
+ }
+
+ @Override
+ public void onResume()
+ {
+ super.onResume();
+
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ Log.d(TAG, "onResume: action=" + action);
+
+ if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
+ Log.d(TAG, "onResume - NDEF discovered");
+ Parcelable[] raw = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+ if (raw != null) {
+ String txt = "NDEF message count: " + raw.length;
+ Log.d(TAG, txt);
+ NdefMessage[] msgs = new NdefMessage[raw.length];
+ for (int i = 0; i < raw.length; i++) {
+ msgs[i] = (NdefMessage) raw[i];
+ NdefRecord rec = msgs[i].getRecords()[0];
+ Log.d(TAG, "MIME type: " + rec.toMimeType());
+ byte[] a = rec.getPayload();
+ Log.d(TAG, "NDEF record: " + byteArrayHex(a));
+ txt += "\nMessage[" + rec.toMimeType() + "]: " +
+ byteArrayHex(a);
+ }
+
+ TextView textView = new TextView(this);
+ textView.setText(txt);
+ textView.setMovementMethod(new ScrollingMovementMethod());
+ setContentView(textView);
+ }
+ }
+ }
+}
diff --git a/wpadebug/src/w1/fi/wpadebug/MainActivity.java b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
new file mode 100644
index 000000000..74e441e96
--- /dev/null
+++ b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
@@ -0,0 +1,183 @@
+/*
+ * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
+ * Copyright (c) 2013, Jouni Malinen
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+package w1.fi.wpadebug;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.os.Bundle;
+import android.view.View;
+import android.content.Intent;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.widget.EditText;
+import android.util.Log;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiConfiguration;
+
+public class MainActivity extends Activity
+{
+ public final static String EXTRA_MESSAGE = "w1.fi.wpadebug.MESSAGE";
+ private static final String TAG = "wpadebug";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+
+ public void runId(View view)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ String message = run("/system/bin/id");
+ if (message == null)
+ return;
+ intent.putExtra(EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ public void runWpaCliCmd(View view)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ EditText editText = (EditText) findViewById(R.id.edit_cmd);
+ String cmd = editText.getText().toString();
+ if (cmd.trim().length() == 0) {
+ show_alert("wpa_cli command", "Invalid command");
+ return;
+ }
+ wpaCmd(view, cmd);
+ }
+
+ public void wpaStatus(View view)
+ {
+ wpaCmd(view, "STATUS");
+ }
+
+ public void wpaPmksa(View view)
+ {
+ wpaCmd(view, "PMKSA");
+ }
+
+ public void wpaScanResults(View view)
+ {
+ wpaCmd(view, "SCAN_RESULTS");
+ }
+
+ public void wpaListNetworks(View view)
+ {
+ wpaCmd(view, "LIST_NETWORKS");
+ }
+
+ public void wpaListCreds(View view)
+ {
+ wpaCmd(view, "LIST_CREDS");
+ }
+
+ public void wpaLogLevelInfo(View view)
+ {
+ wpaCmd(view, "LOG_LEVEL INFO 1");
+ }
+
+ public void wpaLogLevelDebug(View view)
+ {
+ wpaCmd(view, "LOG_LEVEL DEBUG 1");
+ }
+
+ public void wpaLogLevelExcessive(View view)
+ {
+ wpaCmd(view, "LOG_LEVEL EXCESSIVE 1");
+ }
+
+ private void wpaCmd(View view, String cmd)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ String message = run("wpa_cli " + cmd);
+ if (message == null)
+ return;
+ intent.putExtra(EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ private String run(String cmd)
+ {
+ try {
+ Log.d(TAG, "Running external process: " + cmd);
+ Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/mksh-su", "-c", cmd});
+ BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ StringBuffer output = new StringBuffer();
+ int read;
+ char[] buffer = new char[1024];
+ while ((read = reader.read(buffer)) > 0)
+ output.append(buffer, 0, read);
+ reader.close();
+ proc.waitFor();
+ Log.d(TAG, "External process completed - exitValue " +
+ proc.exitValue());
+ return output.toString();
+ } catch (IOException e) {
+ show_alert("Could not run external program",
+ "Execution of an external program failed. " +
+ "Maybe mksh-su was not installed.");
+ return null;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void show_alert(String title, String message)
+ {
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
+ alert.setTitle(title);
+ alert.setMessage(message);
+ alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ }
+ });
+ alert.create().show();
+ }
+
+ public void wifiManagerInfo(View view)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ String message = "WifiState: " + manager.getWifiState() + "\n" +
+ "WifiEnabled: " + manager.isWifiEnabled() + "\n" +
+ "pingSupplicant: " + manager.pingSupplicant() + "\n" +
+ "DhcpInfo: " + manager.getDhcpInfo().toString() + "\n";
+ intent.putExtra(EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ public void wifiInfo(View view)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ WifiInfo wifi = manager.getConnectionInfo();
+ String message = wifi.toString() + "\n" + wifi.getSupplicantState();
+ intent.putExtra(EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ public void wifiConfiguredNetworks(View view)
+ {
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ StringBuilder sb = new StringBuilder();
+ for (WifiConfiguration n: manager.getConfiguredNetworks())
+ sb.append(n.toString() + "\n");
+ intent.putExtra(EXTRA_MESSAGE, sb.toString());
+ startActivity(intent);
+ }
+}