Skip to content

Commit 6ff821d

Browse files
committed
Compiles from source
1 parent 01feb98 commit 6ff821d

24 files changed

+654
-224
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Nexmon CSI utilities for Raspberry Pi
66

77
## Features
88

9-
- Superfast installs with pre-compiled binaries
10-
- Fallback to compiling from source when binaries are not available
11-
- Easy Start/Stop CSI collection with `picsi up` or `picsi down`
12-
- Restore original firmware and connect to WiFi after `picsi down`
13-
- Save CSI to .pcap files
14-
- Forward CSI packets to other devices for faster collection
15-
- Manage your CSI collection configuration with Profiles
9+
- [x] Superfast installs with pre-compiled binaries
10+
- [x] Compiles from source when binaries are not available
11+
- [x] Easy Start/Stop CSI collection with `picsi up` or `picsi down`
12+
- [x] Restore original firmware and connect to WiFi after `picsi down`
13+
- [ ] Save CSI to .pcap files
14+
- [ ] Forward CSI packets to other devices for faster collection
15+
- [ ] Manage your CSI collection configuration with Profiles
1616

1717
## Install
1818

@@ -97,7 +97,6 @@ Only basic CSI collection via profiles will be added first, and other profile fe
9797
be added later.
9898

9999
## Help page
100-
101100
```
102101
Usage: picsi {{ COMMAND | help }} [--option] [--option argument]
103102
COMMAND := {{ install | uninstall | up | down | save | forward | rebuild | help }}
@@ -114,9 +113,9 @@ COMMAND
114113
Installs Nexmon_CSI.
115114
U | uninstall
116115
Uninstalls Nexmon_CSI. Note: Upppercase U.
117-
u | up
116+
e | Enable
118117
Enables CSI collection. WiFi will be disabled.
119-
d | down
118+
d | disable
120119
Disables CSI collection and enables WiFi.
121120
s | save
122121
Save CSI to pcap file

picsi/commands/build.py

Lines changed: 184 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,190 @@
11
__all__ = ["build"]
22

3+
from halo import Halo
4+
from pathlib import Path
35

4-
def build():
6+
from picsi.vendored.mkmanifest import mkmanifest
7+
from picsi.vendored.run_commands import run_commands
8+
from picsi.vendored.get_output import get_output
9+
from picsi.vendored.get_uname import get_uname
10+
11+
12+
def build(
13+
url: str = "https://github.com/seemoo-lab/nexmon_csi",
14+
branch: str = "master",
15+
nexmon_url: str = "https://github.com/seemoo-lab/nexmon.git",
16+
nexmon_branch: str = "master",
17+
):
518
"""
6-
Build Nexmon_CSI
19+
Build Nexmon_CSI from source
720
"""
821

9-
print("build Nexmon_CSI")
22+
Path("/home/pi/.picsi/").mkdir(exist_ok=True)
23+
24+
path_nexmon = Path("/home/pi/.picsi/nexmon")
25+
path_nexmon_csi = Path(
26+
"/home/pi/.picsi/nexmon/patches/bcm43455c0/7_45_189/nexmon_csi"
27+
)
28+
path_nexmon_csi_bin = Path(f"/home/pi/.picsi/bins/{get_uname('-r')}")
29+
30+
nexmon_kversion = ".".join(get_uname("-r").split(".")[:2]) + ".y"
31+
32+
with Halo(spinner="dots") as spinner:
33+
34+
# fmt: off
35+
run_commands([
36+
"# Setting up WiFi",
37+
["/usr/sbin/rfkill", "unblock", "all"],
38+
["/usr/bin/raspi-config", "nonint", "do_wifi_country", "US"],
39+
40+
"# Expanding SD card",
41+
["/usr/bin/raspi-config", "nonint", "do_expand_rootfs"],
42+
43+
"# Installing Dependencies",
44+
["/usr/bin/apt", "update"],
45+
["/usr/bin/apt", "install", "-y",
46+
"automake", "bc", "bison", "flex", "gawk", "git",
47+
"libgmp3-dev", "libncurses5-dev", "libssl-dev",
48+
"libtool-bin", "make", "python-is-python2", "qpdf",
49+
"raspberrypi-kernel-headers", "texinfo",
50+
],
51+
], spinner)
52+
# fmt: on
53+
54+
uname_r = get_uname("-r")
55+
kernel_headers = Path(f"/lib/modules/{uname_r}/build/Kconfig")
56+
57+
if not kernel_headers.is_file():
58+
# fmt: off
59+
run_commands([
60+
"# Installing Kernel headers",
61+
["/usr/bin/wget", "https://raw.githubusercontent.com/RPi-Distro/rpi-source/master/rpi-source", "-O", "/usr/local/bin/rpi-source"],
62+
["/usr/bin/chmod", "+x", "/usr/local/bin/rpi-source"],
63+
["/usr/local/bin/rpi-source", "-q", "--tag-update"],
64+
["/usr/local/bin/rpi-source"]
65+
], spinner)
66+
# fmt: on
67+
68+
# fmt: off
69+
run_commands([
70+
"# Backing up original binaries",
71+
["/usr/bin/mkdir", "-p",
72+
path_nexmon_csi_bin / "makecsiparams/",
73+
path_nexmon_csi_bin / "nexutil/",
74+
path_nexmon_csi_bin / "original/",
75+
path_nexmon_csi_bin / "patched/",
76+
],
77+
["/usr/bin/cp",
78+
"/lib/firmware/brcm/brcmfmac43455-sdio.bin",
79+
path_nexmon_csi_bin / "original/",
80+
],
81+
["/usr/bin/cp",
82+
get_output(["/usr/sbin/modinfo", "brcmfmac", "-n"]),
83+
path_nexmon_csi_bin / "original/",
84+
],
85+
86+
"# Downloading Nexmon",
87+
["/usr/bin/git", "clone", nexmon_url, path_nexmon],
88+
"cd " + str(path_nexmon),
89+
["/usr/bin/git", "checkout", nexmon_branch],
90+
91+
"# Downloading Nexmon_CSI",
92+
["/usr/bin/git", "clone", url, path_nexmon_csi],
93+
"cd " + str(path_nexmon_csi),
94+
["/usr/bin/git", "checkout", branch],
95+
96+
"# Building libISL",
97+
"cd " + str(path_nexmon / "buildtools/isl-0.10/"),
98+
["/usr/bin/autoreconf", "-f", "-i"],
99+
[path_nexmon / "buildtools/isl-0.10/configure"],
100+
["/usr/bin/make"],
101+
["/usr/bin/make", "install"],
102+
["/usr/bin/ln",
103+
"-s", "/usr/local/lib/libisl.so",
104+
"/usr/lib/arm-linux-gnueabihf/libisl.so.10"
105+
],
106+
107+
"# Building libMPFR",
108+
"cd " + str(path_nexmon / "buildtools/mpfr-3.1.4/"),
109+
["/usr/bin/autoreconf", "-f", "-i"],
110+
[path_nexmon / "buildtools/mpfr-3.1.4/configure"],
111+
["/usr/bin/make"],
112+
["/usr/bin/make", "install"],
113+
["/usr/bin/ln",
114+
"-s", "/usr/local/lib/libmpfr.so",
115+
"/usr/lib/arm-linux-gnueabihf/libmpfr.so.4"
116+
],
117+
], spinner)
118+
# fmt: on
119+
120+
env = {
121+
"ARCH": "arm",
122+
"SUBARCH": "arm",
123+
"KERNEL": "kernel7",
124+
"HOSTUNAME": get_uname("-s"),
125+
"PLATFORMUNAME": get_uname("-m"),
126+
"NEXMON_ROOT": str(path_nexmon),
127+
"CC": str(
128+
path_nexmon
129+
/ "buildtools/gcc-arm-none-eabi-5_4-2016q2-linux-armv7l/bin/arm-none-eabi-"
130+
),
131+
"CCPLUGIN": str(path_nexmon / "buildtools/gcc-nexmon-plugin-arm/nexmon.so"),
132+
"ZLIBFLATE": "zlib-flate -compress",
133+
"Q": "@",
134+
"NEXMON_SETUP_ENV": "1",
135+
}
136+
137+
# fmt: off
138+
run_commands([
139+
"# Extracting UCODE, TemplateRAM, and FlashPatches",
140+
"cd " + str(path_nexmon),
141+
["sudo", "-E", "bash", "-c", "/usr/bin/make"],
142+
143+
"# Building Nexmon_CSI",
144+
"cd " + str(path_nexmon_csi),
145+
["sudo", "-E", "bash", "-c", "/usr/bin/make install-firmware"],
146+
147+
"# Building Makecsiparams",
148+
"cd " + str(path_nexmon_csi / "utils/makecsiparams"),
149+
["sudo", "-E", "bash", "-c", "/usr/bin/make"],
150+
151+
"# Building Nexutil",
152+
"cd " + str(path_nexmon / "utilities/nexutil/"),
153+
["sudo", "-E", "bash", "-c", "/usr/bin/make"],
154+
155+
"# Packaging Binaries",
156+
["/usr/bin/cp",
157+
path_nexmon / "utilities/nexutil/nexutil",
158+
path_nexmon_csi_bin / "nexutil/"
159+
],
160+
["/usr/bin/cp",
161+
path_nexmon_csi / "utils/makecsiparams/makecsiparams",
162+
path_nexmon_csi_bin / "makecsiparams/",
163+
],
164+
["/usr/bin/cp",
165+
path_nexmon_csi / ("brcmfmac_" + nexmon_kversion + "-nexmon/brcmfmac.ko"),
166+
path_nexmon_csi_bin / "patched/",
167+
],
168+
["/usr/bin/cp",
169+
path_nexmon_csi / "brcmfmac43455-sdio.bin",
170+
path_nexmon_csi_bin / "patched/",
171+
],
172+
], spinner, env=env)
173+
# fmt: on
174+
175+
# Writes the manifest.toml file
176+
mkmanifest(
177+
path_nexmon_csi_bin,
178+
path_nexmon,
179+
path_nexmon_csi,
180+
url,
181+
branch,
182+
nexmon_url,
183+
nexmon_branch,
184+
)
185+
186+
# fmt: off
187+
run_commands([
188+
["/usr/bin/tar", "-cvJf", f"{path_nexmon_csi_bin}.tar.xz", f"{path_nexmon_csi_bin}"]
189+
], spinner)
190+
# fmt: on

picsi/commands/disable.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
__all__ = ["disable"]
2+
3+
from pathlib import Path
4+
from halo import Halo
5+
6+
from picsi.vendored.run_commands import run_commands
7+
from picsi.vendored.get_uname import get_uname
8+
from picsi.vendored.get_brcmfmacko import get_brcmfmacko
9+
10+
11+
def disable():
12+
"""
13+
Disable CSI collection
14+
"""
15+
16+
with Halo(spinner="dots") as spinner:
17+
18+
Path("/home/pi/.picsi/state").mkdir(exist_ok=True, parents=True)
19+
20+
path_picsi_up = Path("/home/pi/.picsi/state/firmware_is_up")
21+
path_nexmon_csi_bin = Path(f"/home/pi/.picsi/bins/{get_uname('-r')}")
22+
path_brcmfmacko: Path = get_brcmfmacko()
23+
24+
if path_picsi_up.is_file():
25+
path_picsi_up.unlink()
26+
27+
# Enable wpa_supplicant
28+
spinner.text = "Enabling wpa_supplicant"
29+
30+
with open("/etc/dhcpcd.conf", "r") as ifile:
31+
dhcpcd_conf = ifile.read().replace(
32+
"\ndenyinterfaces wlan0\ninterface wlan0\n\tnohook wpa_supplicant\n", ""
33+
)
34+
35+
with open("/etc/dhcpcd.conf", "w") as ofile:
36+
ofile.write(dhcpcd_conf)
37+
38+
# TODO: Investigate disabling CSI collection
39+
# by stopping nexutil
40+
41+
# fmt: off
42+
run_commands([
43+
"# Enabling wpa_supplicant",
44+
["/usr/bin/systemctl", "enable", "--now", "wpa_supplicant"],
45+
["wpa_supplicant", "-B", "-c", "/etc/wpa_supplicant/wpa_supplicant.conf", "-i", "wlan0"],
46+
47+
"# Restoring original firmware",
48+
["/usr/bin/cp", path_nexmon_csi_bin / "original/brcmfmac.ko", f"{path_brcmfmacko}"],
49+
["/usr/bin/cp", path_nexmon_csi_bin / "original/brcmfmac43455-sdio.bin", "/lib/firmware/brcm/brcmfmac43455-sdio.bin"],
50+
["/usr/sbin/depmod", "-a"],
51+
52+
"# Restarting WiFi",
53+
["/usr/sbin/ip", "link", "set", "dev", "wlan0", "down"],
54+
["/usr/sbin/ip", "link", "set", "dev", "wlan0", "up"],
55+
56+
], spinner)
57+
# fmt: on

picsi/commands/down.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)