aboutsummaryrefslogtreecommitdiffstats
path: root/wpadebug/src
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-05-02 21:52:32 (GMT)
committerJouni Malinen <j@w1.fi>2013-05-02 23:09:53 (GMT)
commit4bb4f7cd0048c5315163f9efe060b41897435207 (patch)
treeaeeee651b88cac0566344c9b8b1c74aa09af565c /wpadebug/src
parent741ed9fc2503550270eb3e47803373de5c8994fd (diff)
downloadhostap-4bb4f7cd0048c5315163f9efe060b41897435207.zip
hostap-4bb4f7cd0048c5315163f9efe060b41897435207.tar.gz
hostap-4bb4f7cd0048c5315163f9efe060b41897435207.tar.bz2
wpadebug: Add a Wi-Fi debugging app for Android
This tool can be used to debug Wi-Fi functionality on Android both through the Android framework and through direct access to wpa_supplicant. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpadebug/src')
-rw-r--r--wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java88
-rw-r--r--wpadebug/src/w1/fi/wpadebug/MainActivity.java183
2 files changed, 271 insertions, 0 deletions
diff --git a/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java b/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
new file mode 100644
index 0000000..19cb14b
--- /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 <j@w1.fi>
+ *
+ * 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 0000000..74e441e
--- /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 <j@w1.fi>
+ *
+ * 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);
+ }
+}