-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15237cd
commit 37c2c44
Showing
9 changed files
with
285 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
networksurvey/src/main/java/com/craxiom/networksurvey/constants/csv/WifiCsvConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.craxiom.networksurvey.constants.csv; | ||
|
||
/** | ||
* The constants associated with the Wi-Fi CSV file headers. | ||
* <p> | ||
* The constants in this class are intended to match the constants defined in the | ||
* <a href="https://messaging.networksurvey.app/">Network Survey Messaging API</a>. | ||
*/ | ||
public class WifiCsvConstants extends CellularCsvConstants | ||
{ | ||
private WifiCsvConstants() | ||
{ | ||
} | ||
|
||
public static final String SOURCE_ADDRESS = "sourceAddress"; | ||
public static final String DESTINATION_ADDRESS = "destinationAddress"; | ||
public static final String BSSID = "bssid"; | ||
public static final String BEACON_INTERVAL = "beaconInterval"; | ||
public static final String SERVICE_SET_TYPE = "serviceSetType"; | ||
public static final String SSID = "ssid"; | ||
public static final String SUPPORTED_RATES = "supportedRates"; | ||
public static final String EXT_SUPPORTED_RATES = "extendedSupportedRates"; | ||
public static final String CIPHER_SUITES = "cipherSuites"; | ||
public static final String AKM_SUITES = "akmSuites"; | ||
public static final String ENCRYPTION_TYPE = "encryptionType"; | ||
public static final String WPA = "wps"; | ||
public static final String CHANNEL = "channel"; | ||
public static final String FREQ_MHZ = "frequencyMhz"; | ||
public static final String SIGNAL_STRENGTH = "signalStrength"; | ||
public static final String SNR = "snr"; | ||
public static final String NODE_TYPE = "nodeType"; | ||
public static final String STANDARD = "standard"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
networksurvey/src/main/java/com/craxiom/networksurvey/logging/WifiCsvLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package com.craxiom.networksurvey.logging; | ||
|
||
import static com.craxiom.networksurvey.constants.csv.CsvConstants.SPEED; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.ACCURACY; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.AKM_SUITES; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.ALTITUDE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.BEACON_INTERVAL; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.BSSID; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.CHANNEL; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.CIPHER_SUITES; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.DESTINATION_ADDRESS; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.DEVICE_TIME; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.ENCRYPTION_TYPE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.EXT_SUPPORTED_RATES; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.FREQ_MHZ; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.LATITUDE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.LONGITUDE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.MISSION_ID; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.NODE_TYPE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.RECORD_NUMBER; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SERVICE_SET_TYPE; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SIGNAL_STRENGTH; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SNR; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SOURCE_ADDRESS; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SSID; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.STANDARD; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.SUPPORTED_RATES; | ||
import static com.craxiom.networksurvey.constants.csv.WifiCsvConstants.WPA; | ||
|
||
import android.os.Looper; | ||
|
||
import com.craxiom.messaging.WifiBeaconRecordData; | ||
import com.craxiom.messaging.wifi.CipherSuite; | ||
import com.craxiom.networksurvey.constants.NetworkSurveyConstants; | ||
import com.craxiom.networksurvey.listeners.IWifiSurveyRecordListener; | ||
import com.craxiom.networksurvey.model.WifiRecordWrapper; | ||
import com.craxiom.networksurvey.services.NetworkSurveyService; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* Responsible for taking in Wi-Fi survey records and logging them to a CSV file. | ||
*/ | ||
public class WifiCsvLogger extends CsvRecordLogger implements IWifiSurveyRecordListener | ||
{ | ||
public WifiCsvLogger(NetworkSurveyService networkSurveyService, Looper serviceLooper) | ||
{ | ||
super(networkSurveyService, serviceLooper, NetworkSurveyConstants.CSV_LOG_DIRECTORY_NAME, | ||
NetworkSurveyConstants.WIFI_FILE_NAME_PREFIX, true); | ||
} | ||
|
||
@Override | ||
String[] getHeaders() | ||
{ | ||
return new String[]{DEVICE_TIME, LATITUDE, LONGITUDE, ALTITUDE, SPEED, ACCURACY, | ||
MISSION_ID, RECORD_NUMBER, | ||
SOURCE_ADDRESS, DESTINATION_ADDRESS, BSSID, BEACON_INTERVAL, SERVICE_SET_TYPE, SSID, | ||
SUPPORTED_RATES, EXT_SUPPORTED_RATES, CIPHER_SUITES, AKM_SUITES, ENCRYPTION_TYPE, | ||
WPA, CHANNEL, FREQ_MHZ, SIGNAL_STRENGTH, SNR, NODE_TYPE, STANDARD}; | ||
} | ||
|
||
@Override | ||
String[] getHeaderComments() | ||
{ | ||
return new String[]{"CSV Version=0.1.0"}; | ||
} | ||
|
||
@Override | ||
public synchronized void onWifiBeaconSurveyRecords(List<WifiRecordWrapper> wifiBeaconRecords) | ||
{ | ||
wifiBeaconRecords.forEach(wrapper -> { | ||
try | ||
{ | ||
writeCsvRecord(convertToObjectArray(wrapper), false); | ||
} catch (IOException e) | ||
{ | ||
Timber.e(e, "Could not log the Wi-Fi record to the CSV file"); | ||
} | ||
}); | ||
|
||
try | ||
{ | ||
printer.flush(); | ||
} catch (IOException e) | ||
{ | ||
Timber.e(e, "Could not flush the Wi-Fi records to the CSV file"); | ||
} | ||
} | ||
|
||
/** | ||
* @return A String array that contains the LTE record values that can be written out as a CSV | ||
* row. | ||
*/ | ||
private String[] convertToObjectArray(WifiRecordWrapper wrapper) | ||
{ | ||
WifiBeaconRecordData data = wrapper.getWifiBeaconRecord().getData(); | ||
|
||
final List<CipherSuite> cipherSuitesList = data.getCipherSuitesList(); | ||
String cipherSuites = ""; | ||
if (!cipherSuitesList.isEmpty()) | ||
{ | ||
cipherSuites = cipherSuitesList.stream().map(Enum::toString) | ||
.collect(Collectors.joining(";")); | ||
} | ||
|
||
return new String[]{ | ||
data.getDeviceTime(), | ||
String.valueOf(data.getLatitude()), | ||
String.valueOf(data.getLongitude()), | ||
String.valueOf(data.getAltitude()), | ||
String.valueOf(data.getSpeed()), | ||
String.valueOf(data.getAccuracy()), | ||
data.getMissionId(), | ||
String.valueOf(data.getRecordNumber()), | ||
data.getSourceAddress(), | ||
data.getDestinationAddress(), | ||
data.getBssid(), | ||
data.hasBeaconInterval() ? String.valueOf(data.getBeaconInterval().getValue()) : "", | ||
"", // Service Set Type, not supported by NS | ||
data.getSsid(), | ||
"", // Supported Rates, not supported by NS | ||
"", // Extended Supported Rates, not supported by NS | ||
cipherSuites, | ||
"", // AKM Suites, not supported by NS | ||
data.getEncryptionType().toString(), | ||
data.hasWps() ? String.valueOf(data.getWps().getValue()) : "", | ||
data.hasChannel() ? String.valueOf(data.getChannel().getValue()) : "", | ||
data.hasFrequencyMhz() ? String.valueOf(data.getFrequencyMhz().getValue()) : "", | ||
data.hasSignalStrength() ? String.valueOf(data.getSignalStrength().getValue()) : "", | ||
data.hasSnr() ? String.valueOf(data.getSnr().getValue()) : "", | ||
"", // Node Type, not supported by NS | ||
"" // Standard, not supported by NS | ||
}; | ||
} | ||
} |
Oops, something went wrong.