Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh com 1.5 #296

Closed
wants to merge 199 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
8fa3bdc
first commit.
May 23, 2022
3074de5
Cosmetic changes
May 24, 2022
5ef582b
Addition of new_main.py
May 25, 2022
79e23af
Addition of new_main.py
May 26, 2022
0b9c2cf
mba working as broadcast service
May 26, 2022
38dbb01
MBA
May 27, 2022
00671a4
Signed-off-by: Monika-Research <[email protected]>
Monika-Research May 31, 2022
82414a4
Merge pull request #157 from tiiuae/ca_mesh1.5_main
Monika-Research Jun 3, 2022
a43162f
mesh_com: Add common helpers for connection manager and utils
govindsi Jun 3, 2022
c35a4cc
partially working
Jun 14, 2022
c277953
ap_connect using wpa_supplicant
Jun 14, 2022
ff72b9f
authentication working
Jun 16, 2022
ef4bd58
MA Fully working
Jun 16, 2022
f173852
cosmetic changes
Jun 16, 2022
bc6fea1
cosmetic changes
Jun 16, 2022
7d926e2
adding paths to work under main(1.5)
Jun 16, 2022
2f8a317
minor fixes
Jun 21, 2022
60b85ea
GW Service disable
Jun 21, 2022
c3aae17
Working
Jun 27, 2022
a791922
Working
Jun 27, 2022
e83cdd4
Modification of Server and Client in Continous Authentication Feature…
Suhail-SSRC Jun 30, 2022
6fd880e
descicion engine working
Jul 5, 2022
404494a
last commit
Jul 7, 2022
a3a5066
path call 1_5 instead of 1.5
Jul 25, 2022
fee904d
updating the iptables blocking to be persistent
Jul 27, 2022
22d43a0
Several modifications
Jul 29, 2022
d47a024
Getting all the results on CA
Jul 29, 2022
9d3f853
Working with IP blocking
Aug 5, 2022
bd3e0aa
Fixing CA bugs
Aug 17, 2022
4bd516a
Adding security beat
Aug 24, 2022
a7ce389
Bug fixed on Decision Engine
Sep 2, 2022
d9f16b4
Create ap_config_connectivity.sh
anshul-tii Sep 14, 2022
af3cfe5
Update mesh-11s.sh
martin-tii Sep 15, 2022
1bfea7a
Added main with menu
Sep 26, 2022
7238334
Added termcolor
martin-tii Sep 28, 2022
ebeb0b2
Update Readme.md
anshul-tii Sep 29, 2022
60a78a6
Minor update to Readme.md
anshul-tii Sep 29, 2022
054b506
Modular update
Oct 20, 2022
75f1682
Modular update
Nov 1, 2022
54827d2
Modular update
Nov 1, 2022
f1690ca
Decision Engine Refactor
Nov 4, 2022
974c5c4
Code refactor for demo
Nov 11, 2022
04da7ee
Code refactor for demo
Nov 11, 2022
0c59d15
EC key gen test
SelinaTII Dec 6, 2022
ad812c7
Replaced RSA with EC keys and used the derived secret for CA and encr…
SelinaTII Dec 9, 2022
cf3b278
Merge pull request #209 from tiiuae/Feature/EC_keygen_test
SelinaTII Dec 12, 2022
f9b715a
first commit.
May 23, 2022
1b2459f
Cosmetic changes
May 24, 2022
54cb5d6
Addition of new_main.py
May 25, 2022
a998adf
Addition of new_main.py
May 26, 2022
66bfcca
mba working as broadcast service
May 26, 2022
a82dfd6
MBA
May 27, 2022
b1afc0b
Signed-off-by: Monika-Research <[email protected]>
Monika-Research May 31, 2022
3932150
mesh_com: Add common helpers for connection manager and utils
govindsi Jun 3, 2022
b7a77c1
partially working
Jun 14, 2022
ca534b6
ap_connect using wpa_supplicant
Jun 14, 2022
71e4ace
authentication working
Jun 16, 2022
961caca
MA Fully working
Jun 16, 2022
c942591
cosmetic changes
Jun 16, 2022
36aee90
cosmetic changes
Jun 16, 2022
1416283
adding paths to work under main(1.5)
Jun 16, 2022
804e33f
minor fixes
Jun 21, 2022
5a6e642
GW Service disable
Jun 21, 2022
2b71bf0
Working
Jun 27, 2022
1f047e0
Working
Jun 27, 2022
141fd59
Modification of Server and Client in Continous Authentication Feature…
Suhail-SSRC Jun 30, 2022
28dfd8e
descicion engine working
Jul 5, 2022
905ce31
last commit
Jul 7, 2022
0a9dac4
path call 1_5 instead of 1.5
Jul 25, 2022
38689e3
Secret key file encrption
SelinaTII Dec 14, 2022
576dba1
updating the iptables blocking to be persistent
Jul 27, 2022
41f62bd
Several modifications
Jul 29, 2022
15f42ce
Getting all the results on CA
Jul 29, 2022
e9dd415
Working with IP blocking
Aug 5, 2022
d185317
Fixing CA bugs
Aug 17, 2022
50caf4e
Adding security beat
Aug 24, 2022
e99a981
Bug fixed on Decision Engine
Sep 2, 2022
e218da1
Create ap_config_connectivity.sh
anshul-tii Sep 14, 2022
443337f
Added main with menu
Sep 26, 2022
adb66ad
Added termcolor
martin-tii Sep 28, 2022
9cd6999
Update Readme.md
anshul-tii Sep 29, 2022
7754cfd
Minor update to Readme.md
anshul-tii Sep 29, 2022
6f6bcdb
Modular update
Oct 20, 2022
7a25eee
Modular update
Nov 1, 2022
db2a033
Modular update
Nov 1, 2022
eb3c5ea
Decision Engine Refactor
Nov 4, 2022
f028321
Code refactor for demo
Nov 11, 2022
62fa598
Code refactor for demo
Nov 11, 2022
83452bc
EC key gen test
SelinaTII Dec 6, 2022
6c9babe
Replaced RSA with EC keys and used the derived secret for CA and encr…
SelinaTII Dec 9, 2022
da3500f
Merge pull request #210 from tiiuae/Feature/EC_keygen_test
martin-tii Dec 14, 2022
8145f0c
Merge remote-tracking branch 'origin/feature/1.5' into feature/1.5
martin-tii Dec 14, 2022
73c8050
Gateway service enabled
martin-tii Dec 15, 2022
c358589
cont auth bug fixes, to do: generate ID as hash of mesh IP
SelinaTII Dec 20, 2022
c9bedac
Bug found on the CA
martin-tii Dec 21, 2022
f877ee6
Fixed simultaneous write on secret file during continuous authentication
SelinaTII Dec 23, 2022
8b2bddf
Add spectral base class for spectral scan utility functions
govindsi Dec 26, 2022
47ad4a3
Revert "Add spectral base class for spectral scan utility functions"
govindsi Dec 26, 2022
6b44410
CA bug fixes: secret derivation, mesh neighbor ip and pubKeys
SelinaTII Dec 28, 2022
b7f964b
CA bug fixes: take result from server, avoid premature server process…
SelinaTII Jan 3, 2023
ef47ec5
MA bug fix
SelinaTII Jan 3, 2023
64a0479
Insert results for mesh neighbors in auth table
SelinaTII Jan 5, 2023
cac3a25
Security Beat and Exchange Table Fix for 1 hop neighbors
SelinaTII Jan 11, 2023
4a0cb1e
Modified to run inside docker
martin-tii Jan 13, 2023
3317f90
Python Machine Learning Packets Split
martin-tii Jan 13, 2023
c470536
Modify README.md
martin-tii Jan 13, 2023
a67c824
Improved table exchange algorithm and security beat fix
SelinaTII Jan 16, 2023
ac55a0e
Table exchange
SelinaTII Jan 16, 2023
3424277
Merge remote-tracking branch 'origin/feature/1.5' into Feature/Exchan…
SelinaTII Jan 16, 2023
81bd41f
include security beat in main
SelinaTII Jan 16, 2023
bed2e95
Merge pull request #215 from tiiuae/Feature/Exchange_Table_Fix
martin-tii Jan 16, 2023
0700d3c
Fixin mesh_com build for feature/1.5 branch
joenpera Jan 16, 2023
14ad300
Fixin mesh_com build for feature/1.5 branch
joenpera Jan 16, 2023
2064bca
Merge pull request #217 from tiiuae/mesh_com_build_tech_fix
joenpera Jan 16, 2023
c82461a
Added quarantine to security beat
SelinaTII Jan 17, 2023
8c7d246
Merge pull request #218 from tiiuae/Feature/Exchange_Table_Fix
SelinaTII Jan 17, 2023
2d59502
Avoid pin setting when creating keys
martin-tii Jan 17, 2023
a21c2fe
Bug found in pin decrypt
martin-tii Jan 18, 2023
94216e0
Bug found on gateway service
martin-tii Jan 19, 2023
b34ef3d
Mutual authentication updated
martin-tii Jan 24, 2023
9a06546
Bugs on mutual authentication
martin-tii Jan 24, 2023
8900c51
Functional Tests
SelinaTII Jan 24, 2023
52e6555
test input files
SelinaTII Jan 24, 2023
d02c9a4
Fix issue in mutual authentication, log ness test
SelinaTII Jan 25, 2023
167209c
Merge pull request #220 from tiiuae/Feature/Test
SelinaTII Jan 26, 2023
ea7f1f5
Docker execution bugs fixed
martin-tii Jan 26, 2023
f1ef59b
Added ness_check.krb and ness_fact.kfb
SelinaTII Feb 6, 2023
8d493cc
Merge pull request #223 from tiiuae/Feature/Test
SelinaTII Feb 6, 2023
92b957c
Added sanity tests and changed primitives.get_labels() to derive ID b…
SelinaTII Feb 7, 2023
e52473a
Added sanity tests and changed primitives.get_labels() to derive ID b…
SelinaTII Feb 7, 2023
539b222
Revert "Revert "Add spectral base class for spectral scan utility fun…
govindsi Dec 26, 2022
e6e6aa3
Add csa base class for CSA utility functions
govindsi Jan 5, 2023
df8b648
Merge pull request #225 from tiiuae/feature/ids_spectral_monitor
govindsi Feb 10, 2023
c874e2f
Bug fix for dhcp failure during mutual authentication, use of static …
SelinaTII Feb 14, 2023
6f6d468
Merge pull request #226 from tiiuae/Feature/Test
martin-tii Feb 14, 2023
37e8259
Docker bug fixes: dhcpd failure, file path, automatic port selection …
SelinaTII Feb 16, 2023
a0c99dc
Merge pull request #228 from tiiuae/Feature/docker_bugfix
martin-tii Feb 17, 2023
d4d6bc9
Modification to solve issue of DE
martin-tii Feb 20, 2023
fe03e2a
Fixed Security beat and Quarantine issues
SelinaTII Feb 21, 2023
6519802
Merge pull request #229 from tiiuae/Feature/docker_bugfix
martin-tii Feb 21, 2023
237a682
Bug on the path of entrypoint.sh
martin-tii Feb 21, 2023
f890c10
Bug on the path of entrypoint.sh
martin-tii Feb 21, 2023
740801b
Fixed malicious node decision, Auth AP server for mutual authenticati…
SelinaTII Feb 22, 2023
1aed800
Merge pull request #230 from tiiuae/Feature/docker_bugfix
SelinaTII Feb 22, 2023
268576f
Modify path to run on docker
martin-tii Feb 23, 2023
7a86c77
Added Security Beat to Docker Execution
SelinaTII Feb 28, 2023
33dfd7d
Merge pull request #231 from tiiuae/Feature/docker_bugfix
martin-tii Feb 28, 2023
c335609
Replace old_main.py by main.py
SelinaTII Feb 28, 2023
ef15f0e
Merge pull request #232 from tiiuae/Feature/docker_bugfix
martin-tii Feb 28, 2023
14af172
Automate Docker execution without user intervention
martin-tii Mar 2, 2023
ab5059c
Automate Docker execution without user intervention
martin-tii Mar 3, 2023
3563b1c
duplicated code on line 261
martin-tii Mar 3, 2023
9c6e50f
Merge pull request #236 from tiiuae/automate_startup
martin-tii Mar 3, 2023
a83f9a9
Fixed issues in getting mesh neighbor IPs and automated security beat…
SelinaTII Mar 7, 2023
574cb4f
Merge pull request #241 from tiiuae/Feature/docker_bugfix
SelinaTII Mar 7, 2023
bfd73f4
Code Review and cleanup
martin-tii Mar 13, 2023
6da3786
Merge pull request #246 from tiiuae/automate_startup
martin-tii Mar 13, 2023
240f30c
Fix only_mesh + security beat execution in docker, automatic password…
SelinaTII Mar 14, 2023
2574641
Merge pull request #250 from tiiuae/Feature/docker_bugfix
martin-tii Mar 14, 2023
04899e1
Create Readme.md
martin-tii Mar 15, 2023
8c6110f
Merge pull request #252 from tiiuae/automate_startup
SelinaTII Mar 15, 2023
e6ad328
Merge remote-tracking branch 'origin/develop' into mesh_com_1.5
martin-tii Mar 23, 2023
7a57c55
Merge remote-tracking branch 'origin/develop' into mesh_com_1.5
martin-tii Mar 24, 2023
68c73f6
Update artifactory repository name for new JFrog server
saauvine Mar 24, 2023
e580a4c
ath9k ath10k compatibile + integrate scan config file
dania-tii Mar 23, 2023
d816ec1
spectral capture compatible with ath9k ath10k
dania-tii Mar 23, 2023
917b0c1
create config file with auto detection of scan params
dania-tii Mar 23, 2023
5f52f4d
spectral scan configuration file
dania-tii Mar 23, 2023
2641982
Update config_spectralscan.py
dania-tii Mar 27, 2023
7fc3978
Update SpectralMgr.py
dania-tii Mar 27, 2023
8d7ba77
Update spectral_capture.py
dania-tii Mar 27, 2023
5186fdf
Update SpectralMgr.py
dania-tii Mar 27, 2023
2f61a30
Update config_spectralscan.py
dania-tii Mar 27, 2023
bbe0eae
Update SpectralMgr.py
dania-tii Mar 27, 2023
6ac1899
Update spectral_capture.py
dania-tii Mar 27, 2023
a0eb4ce
Update SpectralMgr.py
dania-tii Mar 27, 2023
1cffb59
Removed mesh.conf from docker
martin-tii May 1, 2023
89808bd
Removed overwriting of mesh.conf while starting mesh for 1.5
SelinaTII May 2, 2023
3c4c66f
Added edge cases for missing frequencies
dania-tii May 30, 2023
524eb4c
Read ath10k radio interface from config file
dania-tii May 30, 2023
3a4b7b2
Automate scan interface channel list detection
dania-tii May 30, 2023
1e9e76f
Update config.yaml
dania-tii May 30, 2023
77e67c9
Added debug print statements
dania-tii May 30, 2023
d97d0ae
Add debug flag from config file
dania-tii May 30, 2023
d4f7bad
Activate and enable scanning interface
dania-tii May 31, 2023
2058ffa
Rename config.yaml file
dania-tii May 31, 2023
fd50d30
Update config.yaml file name to read from
dania-tii May 31, 2023
bc53fdc
Merge remote-tracking branch 'origin/develop' into mesh_com_1.5
martin-tii Jul 31, 2023
44d9a76
Added edge cases for missing frequencies
dania-tii May 30, 2023
685df95
Read ath10k radio interface from config file
dania-tii May 30, 2023
74649b4
Automate scan interface channel list detection
dania-tii May 30, 2023
eb1a0c6
Update config.yaml
dania-tii May 30, 2023
e047ea4
Added debug print statements
dania-tii May 30, 2023
07354ad
Add debug flag from config file
dania-tii May 30, 2023
1657077
Activate and enable scanning interface
dania-tii May 31, 2023
5c24d3d
Rename config.yaml file
dania-tii May 31, 2023
4dc40c7
Update config.yaml file name to read from
dania-tii May 31, 2023
7300312
Merge remote-tracking branch 'origin/mesh_com_1.5' into mesh_com_1.5
martin-tii Sep 15, 2023
b090ebe
Merge remote-tracking branch 'origin/mesh_com_1.5' into mesh_com_1.5
martin-tii Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 108 additions & 144 deletions modules/sc-mesh-secure-deployment/src/1_5/common/SpectralMgr.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,52 @@
#!/usr/bin/python
from datetime import datetime
import pandas as pd
import subprocess
import struct
import math
import time
import yaml
import sys
import os
import stat
import struct
import subprocess
import sys
import time
from datetime import datetime

import pandas as pd

class Spectral:
header_size = 3
type1_packet_size = 17 + 56
type2_packet_size = 24 + 128
type3_packet_size = 26 + 64

# ieee 802.11 constants
sc_wide = 0.3125 # in MHz

VALUES = []

# DRIVER
drivers = ["ath9k", "ath10k"]
driver = os.popen('ls /sys/kernel/debug/ieee80211/phy* | grep ath').read().strip()
if(driver not in drivers):
sys.exit("No driver detected.")
HEADER_SIZE = 3
TYPE1_PACKET_SIZE = 17 + 56
TYPE2_PACKET_SIZE = 24 + 128
TYPE3_PACKET_SIZE = 26 + 64

# CONFIG FILE
with open('config_spectralscan.yaml') as file:
try:
config = yaml.safe_load(file)
debug = config['debug']
interface = config['interface']
except yaml.YAMLError as exc:
print(exc)
sys.exit("Config file error.")
# ieee 802.11 constants
SC_WIDE = 0.3125 # in MHz

DRIVERS = ["ath9k", "ath10k"]
DRIVER = os.popen('ls /sys/kernel/debug/ieee80211/phy* | grep ath').read().strip()
if DRIVER not in DRIVERS: sys.exit("No driver detected.")

# DEBUG CSV FILE
if(debug):
outfile = "spectral_scan"
outfile = "scan"

class Spectral:

def __init__(self):
self.VALUES = dict()

def read(self, spectral_bin, size, all_channels, channels, csv_count, missing_scan_count):
def read(self, spectral_bin, size, channels, scan_count, debug):
self.VALUES = dict()

data = spectral_bin.read(size) # just read 2048 bytes
count = 0
pos = 0
while pos < len(data):
(stype, slen) = struct.unpack_from(">BH", data, pos)
if not ((stype == 1 and slen == self.type1_packet_size) or
(stype == 2 and slen == self.type2_packet_size) or
(stype == 3 and slen == self.type3_packet_size)):
if not ((stype == 1 and slen == TYPE1_PACKET_SIZE) or
(stype == 2 and slen == TYPE2_PACKET_SIZE) or
(stype == 3 and slen == TYPE3_PACKET_SIZE)):
print("skip malformed packet")
break
# 20 MHz
if stype == 1:
if pos >= len(data) - self.header_size - self.type1_packet_size + 1:
if pos >= len(data) - HEADER_SIZE - TYPE1_PACKET_SIZE + 1:
break
pos += self.header_size
pos += HEADER_SIZE
(max_exp, freq, rssi, noise, max_mag, max_index, hweight, tsf) = \
struct.unpack_from(">BHbbHBBQ", data, pos)
pos += 17
Expand All @@ -75,34 +58,35 @@ def read(self, spectral_bin, size, all_channels, channels, csv_count, missing_sc
sum_square_sample = 0
samples = []
for raw_sample in sdata:
if raw_sample == 0:
if raw_sample == 0:
sample = 1
else:
else:
sample = raw_sample << max_exp
sum_square_sample += sample * sample
samples.append(sample)
sum_square_sample += sample * sample
samples.append(sample)

if sum_square_sample == 0:
sum_square_sample = 1
sum_square_sample = 10 * math.log10(sum_square_sample)

sc_total = 56 # HT20: 56 OFDM subcarrier, HT40: 128
first_sc = freq - self.sc_wide * (sc_total / 2 + 0.5)
first_sc = freq - SC_WIDE * (sc_total / 2 + 0.5)

for i, sample in enumerate(samples):
subcarrier_freq = first_sc + i * self.sc_wide
subcarrier_freq = first_sc + i * SC_WIDE
sigval = noise + rssi + 20 * math.log10(sample) - sum_square_sample
self.VALUES[count] = (tsf, subcarrier_freq, noise, rssi, sigval)

if(self.debug):
print("TSF: %d Freq: %d Noise: %d Rssi: %d Signal: %f" % (tsf, subcarrier_freq, noise, rssi, sigval))
if (self.debug):
print("TSF: %d Freq: %d Noise: %d Rssi: %d Signal: %f" % (
tsf, subcarrier_freq, noise, rssi, sigval))
count = count + 1

# 40 MHz
elif stype == 2:
if pos >= len(data) - self.header_size - self.type2_packet_size + 1:
if pos >= len(data) - HEADER_SIZE - TYPE2_PACKET_SIZE + 1:
break
pos += self.header_size
pos += HEADER_SIZE
(chantype, freq, rssi_l, rssi_u, tsf, noise_l, noise_u,
max_mag_l, max_mag_u, max_index_l, max_index_u,
hweight_l, hweight_u, max_exp) = \
Expand Down Expand Up @@ -143,24 +127,22 @@ def read(self, spectral_bin, size, all_channels, channels, csv_count, missing_sc
print("got unknown chantype: %d" % chantype)
raise

first_sc = freq - self.sc_wide * (sc_total / 2 + 0.5)
first_sc = freq - SC_WIDE * (sc_total / 2 + 0.5)
for i, sample in enumerate(samples):
if i < 64:
sigval = noise_l + rssi_l + 20 * math.log10(sample) - sum_square_sample_lower
else:
sigval = noise_u + rssi_u + 20 * math.log10(sample) - sum_square_sample_upper
subcarrier_freq = first_sc + i * self.sc_wide
self.VALUES[count] = (subcarrier_freq, (noise_l + noise_u) / 2, (rssi_l + rssi_u) / 2, sigval, (max_mag_l + max_mag_u)/2)

if(self.debug):
print("TSF: %d Freq: %d Noise: %d Rssi: %d Signal: %f Max Magnitude %d" % (tsf, subcarrier_freq, (noise_l+noise_u)/2, (rssi_l + rssi_u) / 2, sigval, (max_mag_l + max_mag_u)/2))
subcarrier_freq = first_sc + i * SC_WIDE
self.VALUES[count] = (subcarrier_freq, (noise_l + noise_u) / 2, (rssi_l + rssi_u) / 2, sigval, (max_mag_l + max_mag_u) / 2)
count = count + 1

# ath10k
elif stype == 3:
if pos >= len(data) - self.header_size - self.type3_packet_size + 1:
if pos >= len(data) - HEADER_SIZE - TYPE3_PACKET_SIZE + 1:
break
pos += self.header_size
pos += HEADER_SIZE
(chanwidth, freq1, freq2, noise, max_mag, gain_db,
base_pwr_db, tsf, max_index, rssi, relpwr_db, avgpwr_db,
max_exp) = \
Expand All @@ -171,112 +153,94 @@ def read(self, spectral_bin, size, all_channels, channels, csv_count, missing_sc
pos += 64

self.VALUES[count] = (freq1, noise, max_mag, gain_db, base_pwr_db, rssi, relpwr_db, avgpwr_db)

if(self.debug):
print(f"Channel Width: {chanwidth} Freq1: {freq1} Freq2: {freq2} Noise: {noise} Max Magnitude: {max_mag} Gain_db: {gain_db} Base Power_db: {base_pwr_db} TSF: {tsf} Max Index: {max_index} Rssi: {rssi} Rel Power_db: {relpwr_db} Avg Power_db: {avgpwr_db} Max_exp: {max_exp}")
count = count + 1


if(debug):
print(f"Channel Width: {chanwidth} Freq1: {freq1} Freq2: {freq2} Noise: {noise} Max Magnitude: {max_mag} Gain_db: {gain_db} Base Power_db: {base_pwr_db} TSF: {tsf} Max Index: {max_index} Rssi: {rssi} Rel Power_db: {relpwr_db} Avg Power_db: {avgpwr_db} Max_exp: {max_exp}")

vals_list = []
for key, value in self.VALUES.items():
vals_list.append(list(value))

if(self.driver == "ath9k"):
spectral_capture_df = pd.DataFrame(vals_list, columns = ["freq1", "noise", "rssi", "signal", "max magnitude"])
spectral_capture_df = spectral_capture_df.reindex(columns = ["freq1", "noise","signal", "max_magnitude","total_gain_db", "base_pwr_db", "rssi", "relpwr_db", "avgpwr_db"])
if(self.debug):
print(f"all_saved csv {self.outfile}_{csv_count}.csv")
spectral_capture_df.to_csv(f'{self.outfile}_{csv_count}.csv', index=False)
return [all_channels, 0]

elif(self.driver == "ath10k"):
spectral_capture_df = pd.DataFrame(vals_list, columns = ["freq1", "noise", "max_magnitude", "total_gain_db","base_pwr_db", "rssi", "relpwr_db", "avgpwr_db"])


if(spectral_capture_df['freq1'].nunique() != len(channels.split())): # scan is missing channels
missing_scan_count += 1

# first instance of missing scan
if(missing_scan_count == 0):
present_channels = list(map(str, spectral_capture_df['freq1'].unique()))
vals_list_scanning = vals_list

# add remaining missing channels from subsequent scans
elif(missing_scan_count > 0):
scanned_channels = list(map(str, spectral_capture_df['freq1'].unique()))
present_channels += scanned_channels
vals_list_scanning += vals_list


channels_missing_set = set(channels.split()) ^ set(present_channels)
sorted_channels = list(map(int,list(channels_missing_set)))
sorted_channels.sort()
channels = ' '.join(list(map(str, sorted_channels))) # converting to string to pass to do_scan_cmd
return [channels, missing_scan_count]

if(channels == ''): # if all missing channels have been retreived in the scans
present_channels = []
missing_scan_count = 0
if(self.debug):
print(f"cont_saved csv {self.outfile}_{csv_count}.csv")
spectral_capture_df = pd.DataFrame(vals_list_scanning, columns = ["freq1", "noise", "max_magnitude", "total_gain_db","base_pwr_db", "rssi", "relpwr_db", "avgpwr_db"])
spectral_capture_df.to_csv(f'{self.outfile}_{csv_count}.csv', index=False)
return [all_channels, missing_scan_count]

elif(spectral_capture_df['freq1'].nunique() == len(channels.split())): # if scan has all channels
if(self.debug):
print(f"all_saved csv {self.outfile}_{csv_count}.csv")
spectral_capture_df.to_csv(f'{self.outfile}_{csv_count}.csv', index=False)
return [all_channels, missing_scan_count]

if (DRIVER == "ath10k"):
spectral_capture_df = pd.DataFrame(vals_list, columns=["freq1", "noise", "max_magnitude", "total_gain_db",
"base_pwr_db", "rssi", "relpwr_db", "avgpwr_db"])

if(spectral_capture_df["freq1"].nunique() != len(channels.split())):
if(debug):
print("Missing: ", set(channels.split()) ^ set(spectral_capture_df["freq1"].unique()))
valid = 0
return valid

else:
valid = 1
print(f"Scan {scan_count} complete")
spectral_capture_df.to_csv(f'{outfile}_{scan_count}.csv', index=False)
return valid

if (DRIVER == "ath9k"):
spectral_capture_df = pd.DataFrame(vals_list, columns=["freq1", "noise", "rssi", "signal", "max magnitude"])
spectral_capture_df = spectral_capture_df.reindex(
columns=["freq1", "noise", "signal", "max_magnitude", "total_gain_db", "base_pwr_db", "rssi",
"relpwr_db", "avgpwr_db"])
return spectral_capture_df

def get_values(self):
return self.VALUES

def initialize_scan(self):

if(self.driver == "ath9k"):
# cmd_function = "echo background > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"
cmd_function = "echo manual > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"
#cmd_count = "echo 25 > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_count"
cmd_trigger = "echo trigger > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"

subprocess.call(cmd_function, shell=True)
#subprocess.call(cmd_count, shell=True)
subprocess.call(cmd_trigger, shell=True)

elif(self.driver == "ath10k"):
cmd_background = "echo background > /sys/kernel/debug/ieee80211/phy0/ath10k/spectral_scan_ctl"
cmd_trigger = "echo trigger > /sys/kernel/debug/ieee80211/phy0/ath10k/spectral_scan_ctl"

subprocess.call(cmd_background, shell=True)
subprocess.call(cmd_trigger, shell=True)


def execute_scan(self, channels):
#write_fix = f"echo -n disable > /sys/kernel/debug/ieee80211/phy0/{DRIVER}/spectral_scan_ctl"

if (DRIVER == "ath9k"):
# cmd_function = "echo background > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"
cmd_function = "echo manual > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"
# cmd_count = "echo 25 > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_count"
cmd_trigger = "echo trigger > /sys/kernel/debug/ieee80211/phy0/ath9k/spectral_scan_ctl"

#subprocess.call(write_fix, shell=True)
subprocess.call(cmd_function, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)
# subprocess.call(cmd_count, shell=True)
subprocess.call(cmd_trigger, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)

elif (DRIVER == "ath10k"):
file_exists = os.path.exists("/sys/kernel/debug/ieee80211/phy0/ath10k/spectral_scan_ctl")
if (file_exists == False):
print("no file spectral_scan_ctl")
cmd_background = "echo background > /sys/kernel/debug/ieee80211/phy0/ath10k/spectral_scan_ctl"
cmd_trigger = "echo trigger > /sys/kernel/debug/ieee80211/phy0/ath10k/spectral_scan_ctl"

#subprocess.call(write_fix, shell=True)
subprocess.call(cmd_background, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)
subprocess.call(cmd_trigger, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)

def execute_scan(self, interface, channels):
scan = False
do_scan_cmd = f"iw dev {self.interface} scan freq {channels}"
do_scan_cmd = f"iw dev {interface} scan freq {channels} flush"
interface_up = f"ip link set dev {interface} up" # activate and enable the interface
print(do_scan_cmd)

while(scan == False):
while (scan == False):
try:
proc = subprocess.run(do_scan_cmd, shell=True, stdout=subprocess.DEVNULL, check=True)
#proc = subprocess.run(do_scan_cmd, shell=True, stdout=subprocess.DEVNULL)
subprocess.call(interface_up, shell=True)
subprocess.run(do_scan_cmd, shell=True, stderr=subprocess.STDOUT,stdout=subprocess.DEVNULL, check=True)
scan = True
except:
time.sleep(0.1)
scan = False

if(scan == True):
print(f"Scan time {datetime.now()}")
if (scan == True):
break

#cmd_background = f"echo -n background > /sys/kernel/debug/ieee80211/phy0/{DRIVER}/spectral_scan_ctl"
#cmd_scan = f"echo -n trigger > /sys/kernel/debug/ieee80211/phy0/{DRIVER}/spectral_scan_ctl"
cmd_disable = f"echo disable > /sys/kernel/debug/ieee80211/phy0/{DRIVER}/spectral_scan_ctl"
cmd_dump = f"cat /sys/kernel/debug/ieee80211/phy0/{DRIVER}/spectral_scan0 > /tmp/data"

cmd_scan = f"echo trigger > /sys/kernel/debug/ieee80211/phy0/{self.driver}/spectral_scan_ctl"
cmd_dump = f"cat /sys/kernel/debug/ieee80211/phy0/{self.driver}/spectral_scan0 > /tmp/data"

subprocess.call(cmd_scan, shell=True)
subprocess.call(cmd_dump, shell=True)

#subprocess.call(cmd_background, shell=True)
#subprocess.call(cmd_scan, shell=True)
subprocess.call(cmd_disable, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)
subprocess.call(cmd_dump, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)

@staticmethod
def file_close(file_pointer):
Expand All @@ -285,8 +249,8 @@ def file_close(file_pointer):
@staticmethod
def file_open(fn="data"):
file_exists = os.path.exists(fn)
if(file_exists):
if (file_exists):
return open(fn, 'rb')
elif(file_exists == False):
elif (file_exists == False):
os.system("touch " + fn)
return open(fn, 'rb')
Loading
Loading