aboutsummaryrefslogtreecommitdiffstats
path: root/wpadebug
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-05-04 23:46:41 (GMT)
committerJouni Malinen <j@w1.fi>2013-05-04 23:46:41 (GMT)
commita9008e43e555816aaf1f5a31d1cd22ad671b2e76 (patch)
tree509029a4d47d2774cf872bad049fe29639dc98f4 /wpadebug
parentcb54718c501e2b37231a849a0469deddbf18225a (diff)
downloadhostap-a9008e43e555816aaf1f5a31d1cd22ad671b2e76.zip
hostap-a9008e43e555816aaf1f5a31d1cd22ad671b2e76.tar.gz
hostap-a9008e43e555816aaf1f5a31d1cd22ad671b2e76.tar.bz2
wpadebug: Add generic control interface command mechanism
Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpadebug')
-rw-r--r--wpadebug/AndroidManifest.xml4
-rw-r--r--wpadebug/README3
-rw-r--r--wpadebug/res/layout/main.xml36
-rw-r--r--wpadebug/res/raw/wpa_commands.txt5
-rw-r--r--wpadebug/src/w1/fi/wpadebug/MainActivity.java31
-rw-r--r--wpadebug/src/w1/fi/wpadebug/WpaCommandListActivity.java106
6 files changed, 127 insertions, 58 deletions
diff --git a/wpadebug/AndroidManifest.xml b/wpadebug/AndroidManifest.xml
index f351b08..227f182 100644
--- a/wpadebug/AndroidManifest.xml
+++ b/wpadebug/AndroidManifest.xml
@@ -32,5 +32,9 @@
android:label="Command list"
android:parentActivityName="w1.fi.wpadebug.MainActivity">
</activity>
+ <activity android:name="w1.fi.wpadebug.WpaCommandListActivity"
+ android:label="WPA command list"
+ android:parentActivityName="w1.fi.wpadebug.MainActivity">
+ </activity>
</application>
</manifest>
diff --git a/wpadebug/README b/wpadebug/README
index ada07ba..5d91fb7 100644
--- a/wpadebug/README
+++ b/wpadebug/README
@@ -50,6 +50,9 @@ arbitrary shell commands to be executed. This text file need to be in
example:
version@cat /proc/version
+Similarly, /data/local/wpadebug.wpacmds can be used to define additional
+wpa_supplicant control interface commands.
+
Uninstallation
--------------
diff --git a/wpadebug/res/layout/main.xml b/wpadebug/res/layout/main.xml
index b3337e4..76841b1 100644
--- a/wpadebug/res/layout/main.xml
+++ b/wpadebug/res/layout/main.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
@@ -39,36 +39,6 @@
android:text="wpa_supplicant commands"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="status"
- android:onClick="wpaStatus"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="PMKSA"
- android:onClick="wpaPmksa"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="networks"
- android:onClick="wpaListNetworks"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="creds"
- android:onClick="wpaListCreds"
- />
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
@@ -76,8 +46,8 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="scanres"
- android:onClick="wpaScanResults"
+ android:text="wpa_supplicant commands"
+ android:onClick="runWpaCommands"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
diff --git a/wpadebug/res/raw/wpa_commands.txt b/wpadebug/res/raw/wpa_commands.txt
new file mode 100644
index 0000000..6fc043f
--- /dev/null
+++ b/wpadebug/res/raw/wpa_commands.txt
@@ -0,0 +1,5 @@
+Status@STATUS
+PMKSA cache@PMKSA
+Networks@LIST_NETWORKS
+Creds@LIST_CREDS
+Scan results@SCAN_RESULTS
diff --git a/wpadebug/src/w1/fi/wpadebug/MainActivity.java b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
index f135440..0c601d3 100644
--- a/wpadebug/src/w1/fi/wpadebug/MainActivity.java
+++ b/wpadebug/src/w1/fi/wpadebug/MainActivity.java
@@ -47,6 +47,12 @@ public class MainActivity extends Activity
startActivity(intent);
}
+ public void runWpaCommands(View view)
+ {
+ Intent intent = new Intent(this, WpaCommandListActivity.class);
+ startActivity(intent);
+ }
+
public void runWpaCliCmd(View view)
{
Intent intent = new Intent(this, DisplayMessageActivity.class);
@@ -59,31 +65,6 @@ public class MainActivity extends Activity
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");
diff --git a/wpadebug/src/w1/fi/wpadebug/WpaCommandListActivity.java b/wpadebug/src/w1/fi/wpadebug/WpaCommandListActivity.java
new file mode 100644
index 0000000..4ad9b2d
--- /dev/null
+++ b/wpadebug/src/w1/fi/wpadebug/WpaCommandListActivity.java
@@ -0,0 +1,106 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Scanner;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.ArrayAdapter;
+import android.widget.Toast;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+
+public class WpaCommandListActivity extends ListActivity
+{
+ private static final String TAG = "wpadebug";
+ private static final String cmdfile = "/data/local/wpadebug.wpacmds";
+
+ private void read_commands(ArrayList<CmdList> list, Scanner in)
+ {
+ in.useDelimiter("@");
+ while (in.hasNext()) {
+ String title = in.next();
+ String cmd = in.nextLine().substring(1);
+ list.add(new CmdList(title, cmd));
+ }
+ in.close();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ ArrayList<CmdList> list = new ArrayList<CmdList>();
+
+ FileReader in;
+ try {
+ in = new FileReader(cmdfile);
+ read_commands(list, new Scanner(in));
+ } catch (IOException e) {
+ Toast.makeText(this, "Could not read " + cmdfile,
+ Toast.LENGTH_SHORT).show();
+ }
+
+ InputStream inres = getResources().openRawResource(R.raw.wpa_commands);
+ read_commands(list, new Scanner(inres));
+
+ ArrayAdapter<CmdList> listAdapter;
+ listAdapter = new ArrayAdapter<CmdList>(this, android.R.layout.simple_list_item_1, list);
+
+ setListAdapter(listAdapter);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id)
+ {
+ CmdList item = (CmdList) getListAdapter().getItem(position);
+ Toast.makeText(this, "Running: " + item.command,
+ Toast.LENGTH_SHORT).show();
+ String message = run(item.command);
+ if (message == null)
+ return;
+ Intent intent = new Intent(this, DisplayMessageActivity.class);
+ intent.putExtra(MainActivity.EXTRA_MESSAGE, message);
+ startActivity(intent);
+ }
+
+ private String run(String cmd)
+ {
+ try {
+ Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/mksh-su", "-c", "wpa_cli " + 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();
+ return output.toString();
+ } catch (IOException e) {
+ Toast.makeText(this, "Could not run command",
+ Toast.LENGTH_LONG).show();
+ return null;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}