blob: d8079b970c13f6055344adb87d2ea70e27743388 (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
//
// Copyright 2017, 2018 Filippo "Fil" Bergamo <fil.bergamo@riseup.net>
//
// This file is part of RepWifiApp.
//
// RepWifiApp is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RepWifiApp is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RepWifiApp. If not, see <http://www.gnu.org/licenses/>.
//
// ********************************************************************
package fil.libre.repwifiapp.network;
import fil.libre.repwifiapp.helpers.Logger;
import fil.libre.repwifiapp.helpers.RootCommand;
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() {
Logger.logDebug("startWpaSupplicant():");
if (isRunning()){
return true;
}
// needs root (for wpa_supplicant)
if (RootCommand.executeRootCmd(BASE_COMMNAD)) {
return true;
} else {
Logger.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) {
Logger.logError("Exception during isWpaSupplicantRunning()", e);
retval = false;
}
return retval;
}
}
|