aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/fil/libre/repwifiapp/helpers/WpaSupplicant.java
blob: 1dfe449a953b032b01e47524df2ac46309dcb9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fil.libre.repwifiapp.helpers;


public abstract class WpaSupplicant {

    public static final String INTERFACE_NAME = "wlan0";
    public static final String WORKDIR = "/data/misc/wifi";
    public static final String PID_FILE = WORKDIR + "/pidfile";
    public static final String SOCKET_DIR = WORKDIR + "/sockets/";
    public static final String SOFTAP_FILE = WORKDIR + "/softap.conf";
    public static final String P2P_CONF = WORKDIR + "/p2p_supplicant.conf";
    public static final String WPA_CONF = WORKDIR + "/wpa_supplicant.conf";
    public static final String ENTROPY_FILE = WORKDIR + "/entropy.bin";
    public static final String OVERLAY_FILE = "/system/etc/wifi/wpa_supplicant_overlay.conf";

    protected static final String BASE_COMMNAD = "wpa_supplicant -B -dd -i" + INTERFACE_NAME + " -C" + SOCKET_DIR + " -P" + PID_FILE
                    + " -I" + OVERLAY_FILE + " -e" + ENTROPY_FILE;

    public static boolean start() {

        Utils.logDebug("startWpaSupplicant():");

        // needs root (for wpa_supplicant)
        if (RootCommand.executeRootCmd(BASE_COMMNAD)) {
            return true;
        } else {
            Utils.logDebug("Failed to start wpa");
            return false;
        }

    }

    public static boolean kill(){
        return RootCommand.executeRootCmd("killall -SIGINT wpa_supplicant");
    }
    
    public static boolean isRunning() {

        boolean retval = false;

        try {

            RootCommand su = new RootCommand("pidof wpa_supplicant");
            if (su.execute() == 0) {

                if (su.getOutput().trim().equals("")) {
                    retval = false;
                } else {
                    retval = true;
                }

            } else {
                retval = false;
            }

        } catch (Exception e) {
            Utils.logError("Exception during isWpaSupplicantRunning()", e);
            retval = false;
        }

        return retval;

    }

}