Implement 0010 RPM/L2/WCD/UART deep-standby, Adreno 304 ICC/SMMU fixes, and C11 autostart daemons

- patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch and device DTS/DTB files (nokia-{argon,beatles,beatles-cover,coconut,sparkler,leo}): vMPM APSS RPM sleep, L2 SAW2 collapse, WCD-digital runtime PM, PM8909 LDO seeding, ttyMSM0 disable, dynamic msm_gpu gfx-mem BIMC interconnect scaling (mas_oxili), and qcom_iommu context restore + atomic TLB flush on resume.
- Replace Python/shell autostart loops with compiled C11 ARM ELF daemons (bananarchy-dsds, bananarchy-modemmonitor, bananarchy-soundmonitor, bananarchy-notifmonitor, bananarchy-run-aligned, bananarchy-session-loop) plus scripts/test-dsds-daemon.py.
- Update scripts/check-rebuild.sh, CHANGELOG.md, BATTERY-OPTIMIZATION-ANALYSIS.md, MANUAL.md, README.md, and AGENTS.md with verified a1114 (carbonara) image/archive pins and guards.
This commit is contained in:
Luxferre committed 2026-11-13 18:23:14 +02:00
1 parent 96c66bf0c6
commit 2ae4ef34a2
86 files changed
+99754 -94563

No files matched your search

+5 -3
View File
@@ -62,9 +62,11 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `
- Keep power/network behaviour event-driven: `superctl disable sxmo_networkmonitor`, no long `nmcli device monitor`, no - Keep power/network behaviour event-driven: `superctl disable sxmo_networkmonitor`, no long `nmcli device monitor`, no
infinite wakelocks, no forced `sxmo.noidle`/`sxmo.nosuspend`, lz4 zram via `/usr/bin/zramstart`, and infinite wakelocks, no forced `sxmo.noidle`/`sxmo.nosuspend`, lz4 zram via `/usr/bin/zramstart`, and
`vm.compaction_proactiveness=0`. GPS resolves through `bananarchy-gps-modem.sh`, never `mmcli -m any`. `vm.compaction_proactiveness=0`. GPS resolves through `bananarchy-gps-modem.sh`, never `mmcli -m any`.
- Keep idle daemons as compiled C ARM ELF binaries (`bananarchy-lid`, `bananarchy-cover-idle`, - Keep idle and autostart daemons as compiled C ARM ELF binaries (`bananarchy-lid`, `bananarchy-cover-idle`,
`bananarchy-volume-keys`), not Python. Preserve `/run/bananarchy/lid-state`, the cover socket protocol, `FBIOBLANK`, `bananarchy-volume-keys`, `bananarchy-dsds`, `bananarchy-modemmonitor`, `bananarchy-soundmonitor`,
cover diagnostics, and `scripts/test-cover-idle.py`. `bananarchy-notifmonitor`, `bananarchy-run-aligned`, `bananarchy-session-loop`), not Python or `/bin/sh` loops.
Preserve `/run/bananarchy/lid-state`, the cover socket protocol, `FBIOBLANK`, cover diagnostics,
`scripts/test-cover-idle.py`, and `scripts/test-dsds-daemon.py`.
- Keep the zero-lag plugin model: preloaded resident daemons guarded by lock/FIFO, `poll()` at 0% CPU, offscreen - Keep the zero-lag plugin model: preloaded resident daemons guarded by lock/FIFO, `poll()` at 0% CPU, offscreen
`240x296` Pixmaps at `Y=24`, `PluginTheme`, `RELOAD_THEME`, idle blank/lock helpers, the 350 ms `dwm` wake guard, and `240x296` Pixmaps at `Y=24`, `PluginTheme`, `RELOAD_THEME`, idle blank/lock helpers, the 350 ms `dwm` wake guard, and
startup keyboard-grab cleanup without a background poller. startup keyboard-grab cleanup without a background poller.
+76
View File
@@ -1416,3 +1416,79 @@ beacon wakeups, and stale `drm_mipi_dbi.ko` active:
`scripts/check-rebuild.sh` now build, compress, install into `overlay/rootfs` `scripts/check-rebuild.sh` now build, compress, install into `overlay/rootfs`
and target rootfs/initramfs, and verify `drm_mipi_dbi.ko.zst` alongside and target rootfs/initramfs, and verify `drm_mipi_dbi.ko.zst` alongside
`panel-mipi-dbi.ko.zst`. `panel-mipi-dbi.ko.zst`.
---
## 22. Pass 1 + Pass 2 RPM sleep (`vMPM` + L2 SAW2), BIMC PLL / WCD-digital / LDO cleanup, and UART/Wi-Fi standby optimizations (`0010`)
On-device clock and genpd telemetry after `0009` (`pm_genpd_summary` +
`clk_summary`, losing ~`4.8%/h`) exposed the remaining blockers preventing XO/CX/MX
and BIMC DDR from collapsing during deep idle (while revealing that an active `mas_oxili` GPU without a `gfx-mem` interconnect vote starved when `cpu0` dropped to `19.2 MHz` BIMC XO):
`qcom_stats`/`qcom_rpm_master_stats` were not wired in DT, `gpu@1c00000` lacked `gfx-mem` BIMC scaling,
`gcc_blsp1_uart1_apps_clk` (`ttyMSM0` / `serial@78af000`) kept `gpll0` active
at `enable_count = 3`, and `cpuidle-qcom-spm` stopped at per-core `SPC` without
vMPM timer programming or last-man L2 SAW2 shutdown.
1. **RPM LPM handoff (`qcom,mpm` vMPM + last-man `cpuidle-qcom-spm` + L2 SAW2,
Pass 2)**: `0010` wires MSM8909 `qcom,mpm` (`sram@60000` sub-slices `0x150`
APSS, `0x1d0` vMPM, `0x1150` MPSS, `0x2150` PRONTO; wakeup-parent on TLMM;
`qcom,msm8916-rpm-stats` + `CONFIG_QCOM_RPM_MASTER_STATS=y` `rpm-master-stats`),
adds the L2 SAW2 node (`power-manager@b012000`, `qcom,msm8909-saw2-v3.0-scu`)
linked via `l2-cache` `qcom,saw` across all six MSM8905/MSM8909 DTS files,
fixes SAW2 v3.0 `0x3B` / `PC_MODE` / `SLP_CMD_MODE` indexing and XPU-locked
L2 readback guards, guards `qcom_mpm_handler()` against `NULL` `irq_desc`
mappings for pre-enabled MPM pins (`49`, `58`, `62`), keeps per-CPU SPM in
`PM_SLEEP_MODE_SPC` even when `l2_sleep=0`, and teaches
`cpuidle-qcom-spm` to enter APSS RPM/vMPM sleep (`rpm_sleep=1`,
`rpm_min_residency_us=3000`) and L2 SAW2 collapse (`l2_sleep=1`,
`QCOM_SCM_CPU_PWR_DOWN_L2_OFF`) when the last online CPU enters idle, gated on
`/sys/module/cpuidle_qcom_spm/parameters/screen_off` (toggled by
`bananarchy-display-power-sync` and `bananarchy-power-policy.sh`) plus
`qcom_msm8909_gdsc_is_active()` in `gcc-msm8909.c` so RPM/L2 collapse never
fires while `oxili_gdsc`/`mdss_gdsc`/`venus_gdsc`/`vfe_gdsc` or the panel
are active, uses `ktime_sub(tick_nohz_get_next_hrtimer(), ktime_get())` to
avoid `tick_nohz` warnings, and keeps zero `vermagic`/`Module.symvers` ABI
changes (`# CONFIG_SUSPEND is not set` unchanged).
2. **Adreno 304 `gfx-mem` interconnect scaling, `qcom_iommu` non-genpd resume/TLB
fix, GDSC recovery cycle, WCD-digital runtime PM, and PM8909 LDO seeding
(Pass 1)**:
- `qcom-msm8909.dtsi` and all six device DTS files wire `gpu@1c00000`
`interconnects` (`MAS_OXILI -> SLV_EBI`, `"gfx-mem"`). Instead of holding
BIMC at `400 MHz` statically from probe, `msm_gpu_pm_resume()` votes
`Bps_to_icc(gpu->fast_rate) * 8` before enabling GPU clocks and
`msm_gpu_pm_suspend()` drops the vote to `0` after disabling clocks so
idle/screen-off BIMC still reaches `19.2 MHz` XO while active rendering
and DPMS transitions never starve the GPU.
- `qcom_iommu.c` wraps blocking `qcom_iommu_map()` calls with runtime PM
and saves/restores non-secure context bank registers + flushes
`ARM_SMMU_CB_S1_TLBIASID` in `qcom_iommu_resume()` even when
`dev->pm_domain` is `NULL` (`VDD_CX` collapse on `1f08000.iommu`).
- `gcc-msm8909.c` exposes `qcom_msm8909_gdsc_is_active()`, and
`adreno_gpu.c` (`adreno_recover()`) cycles `dev_pm_genpd_synced_poweroff()`
+ `pm_runtime_put_sync()`/`pm_runtime_get_sync()` on the GPU device so
`oxili_gdsc` resets cleanly on ringbuffer lockups.
- `msm8916-wcd-digital.c` sets `.idle_bias_on = 0`, adds `REGCACHE_FLAT` and
`200 ms` runtime PM autosuspend + `RUNTIME_PM_OPS`.
- `qcom_smd-regulator.c` seeds `vreg->is_enabled = 1` for PM8909 `l14`,
`l15`, and `l18` in `rpm_regulator_init_vreg()` so unused rails drop cleanly
after `regulator_late_cleanup`.
3. **Serial UART console (`ttyMSM0` / `serial@78af000`) disabled**: disabled
`serial@78af000` and cleared `chosen/stdout-path` in all kernel and device
DTS files and removed `console=ttyMSM0,115200` from all `kernel-cmdline.conf`
and `50-device-*.conf` fragments so `blsp1_uart1_apps_clk` no longer holds
`gpll0` (`enable_count = 0`).
4. **Runtime policy & telemetry additions (`bananarchy-power-policy.conf` /
`.sh`)**: added `CPU_RPM_SLEEP=1`, `CPU_L2_SLEEP=1`,
`WIFI_SCREEN_OFF_IPV6_MUTE=1` (mutes unsolicited IPv6 RAs on `wlan0` during
screen-off whenever `wlan0` already holds an IPv4 address, restored on wake),
and opt-in `WIFI_STANDBY_RAT=keep|gsm` (parks QMI NAS mode preference to GSM
after 30 s dark while `wlan0` is `up`, restored on wake), plus `status`
readouts for `cpuidle_qcom_spm`, `/sys/kernel/debug/qcom_stats/*`, and
`/sys/kernel/debug/qcom_rpm_master_stats/*`.
5. **Compiled C11 autostart daemons (`bananarchy-dsds`, monitors, session)**:
replaced `python3 - dsds-daemon`, `sxmo_modemmonitor.sh`,
`sxmo_soundmonitor.sh` (`evtest`), `sxmo_notifs.sh monitor` (`inotifywait`),
`sxmo_run_aligned.sh` (`sxmo_aligned_sleep`), and the
`bananarchy-x11-session.sh` tail loop with 0%-CPU compiled C11 ARM ELF
binaries (`poll(..., -1)` / `inotify` / `nanosleep`) built by
`scripts/build-bananarchy-daemons.sh`.
+8 -2
View File
@@ -14,7 +14,13 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
Upcoming release build (`a1114` / `carbonara` via `scripts/version.sh`) targeting both **Nokia 8110 4G (`nokia-argon`)** and **Nokia 2720 Flip (`nokia-beatles`)** while keeping `a1111` (`lennon`) as the current published release. Upcoming release build (`a1114` / `carbonara` via `scripts/version.sh`) targeting both **Nokia 8110 4G (`nokia-argon`)** and **Nokia 2720 Flip (`nokia-beatles`)** while keeping `a1111` (`lennon`) as the current published release.
### Hardware, kernel, and firmware deep-standby fixes (`0008` and `0009`) ### Hardware, kernel, and firmware deep-standby fixes (`0008`, `0009`, and `0010`)
- **Pass 1 + Pass 2 RPM sleep (`vMPM` + L2 SAW2), BIMC PLL / WCD-digital / LDO cleanup, Adreno 304 active-display guard, and UART disable (`0010`)**:
- **Last-man APSS RPM (`vMPM`) and L2 SAW2 standby collapse (`0010`)**: enabled `CONFIG_QCOM_RPM_MASTER_STATS=y`, wired `qcom,mpm` (`sram@60000` sub-slices `0x150`/`0x1d0`/`0x1150`/`0x2150`, TLMM `wakeup-parent`, `qcom,msm8916-rpm-stats`, `rpm-master-stats`) and L2 SAW2 (`power-manager@b012000`, `qcom,msm8909-saw2-v3.0-scu` linked via `l2-cache` `qcom,saw`) across kernel and all six device DTS files; fixed SAW2 v3.0 `0x3B` / `PC_MODE` / `SLP_CMD_MODE` indexing and XPU-locked L2 readback guards; guarded `qcom_mpm_handler()` against `NULL` `irq_desc` mappings on pre-enabled MPM pins (`49`, `58`, `62`); gated `cpuidle-qcom-spm` last-man APSS RPM (`rpm_sleep=1`, `rpm_min_residency_us=3000`) and L2 collapse (`l2_sleep=1`, `QCOM_SCM_CPU_PWR_DOWN_L2_OFF`) on both `qcom_msm8909_gdsc_is_active()` (`oxili_gdsc`/`mdss_gdsc`/`venus_gdsc`/`vfe_gdsc`) and `cpuidle_qcom_spm/parameters/screen_off` (toggled by `bananarchy-display-power-sync` and `bananarchy-power-policy.sh`) so active displays/GPUs never suffer L2/shared-clock collapse; and switched the next-timer check to `ktime_sub(tick_nohz_get_next_hrtimer(), ktime_get())` (`tick_nohz` warning fixed) with `# CONFIG_SUSPEND is not set` and module `vermagic` unchanged.
- **Adreno 304 `gfx-mem` interconnect scaling, `qcom_iommu` non-genpd resume/TLB fix, GDSC recovery cycle, WCD-digital runtime PM, and PM8909 LDO seeding (`0010`)**: wired `bimc`/`pcnoc`/`snoc` nodes and Adreno 304 `gfx-mem` interconnect (`MAS_OXILI -> SLV_EBI`) in `qcom-msm8909.dtsi` and all six device DTS files, moved `a3xx_gpu_init()`'s static `icc_set_bw()` into `msm_gpu_pm_resume()` / `msm_gpu_pm_suspend()` (`Bps_to_icc(gpu->fast_rate) * 8` while active, `0` when runtime-suspended so BIMC still drops to `19.2 MHz` XO when idle without starving Adreno 304 during `powersave`/DPMS transitions), guarded blocking `qcom_iommu_map()` calls with runtime PM, saved/restored non-secure context bank registers + `ARM_SMMU_CB_S1_TLBIASID` in `qcom_iommu_resume()` for non-genpd `VDD_CX` SMMUs (`1f08000.iommu`), exposed `qcom_msm8909_gdsc_is_active()` in `gcc-msm8909.c`, added `dev_pm_genpd_synced_poweroff()` + `pm_runtime_put_sync()`/`pm_runtime_get_sync()` in `adreno_recover()` so `oxili_gdsc` resets cleanly on ringbuffer lockups, added `.idle_bias_on = 0` + `REGCACHE_FLAT` + `200 ms` runtime autosuspend (`RUNTIME_PM_OPS`) in `msm8916-wcd-digital.c`, and seeded `vreg->is_enabled = 1` for PM8909 `l14`, `l15`, and `l18` in `qcom_smd-regulator.c`.
- **Disable `ttyMSM0` (`serial@78af000`) and extend runtime power policy**: disabled `serial@78af000` + cleared `chosen/stdout-path` in all DTS files and removed `console=ttyMSM0,115200` from all `kernel-cmdline.conf` and `50-device-*.conf` fragments; added `CPU_RPM_SLEEP=1`, `CPU_L2_SLEEP=1`, `WIFI_SCREEN_OFF_IPV6_MUTE=1` (mutes unsolicited `wlan0` IPv6 RAs while dark on IPv4 networks, restored on wake), opt-in `WIFI_STANDBY_RAT=keep|gsm`, and `cpuidle_qcom_spm` / `qcom_stats` / `qcom_rpm_master_stats` telemetry to `bananarchy-power-policy.conf` and `bananarchy-power-policy.sh`.
- **Compiled C11 autostart daemons (`bananarchy-dsds` and monitors)**: replaced `python3 - dsds-daemon`, `sxmo_modemmonitor.sh`, `sxmo_soundmonitor.sh` (`evtest`), `sxmo_notifs.sh monitor` (`inotifywait`), `sxmo_run_aligned.sh` (`sxmo_aligned_sleep`), and the `bananarchy-x11-session.sh` tail loop with 0%-CPU compiled C11 ARM ELF binaries (`bananarchy-dsds`, `bananarchy-modemmonitor`, `bananarchy-soundmonitor`, `bananarchy-notifmonitor`, `bananarchy-run-aligned`, `bananarchy-session-loop`) plus thin `exec` compatibility shims, `doas` rule, and `superd` service units, leaving zero Python or `/bin/sh` daemons on autostart; guarded by `scripts/test-dsds-daemon.py` and `scripts/check-rebuild.sh`.
- **MSM8909 RPM interconnect bus scaling (`CONFIG_INTERCONNECT_QCOM_MSM8909=y`)**: enabled `CONFIG_INTERCONNECT_QCOM=y`, `CONFIG_INTERCONNECT_QCOM_MSM8909=y`, and `CONFIG_INTERCONNECT_QCOM_SMD_RPM=y`, marked `msm8909_bimc`, `msm8909_pcnoc`, and `msm8909_snoc` `.keep_alive = true` (`19.2 MHz` active floor, `0` in `QCOM_SMD_RPM_SLEEP_STATE`), initialized `qp->bus_clk_rate[*]` to `U32_MAX` in `qnoc_probe()` so `icc_sync_state` clears `clk_smd_rpm_handoff()`'s `INT_MAX` sleep-set vote in RPM, wired `interconnect@400000`, `interconnect@500000`, `interconnect@580000`, `cpus` `interconnects`, and `cpu-opp-table` `opp-peak-kBps` across all six MSM8905/MSM8909 DTS files, and lowered the `199999951 Hz` idle CPU OPP `opp-peak-kBps` floor from `<0xc3500>` (`100 MHz` BIMC) to `<0x25800>` (`153,600 kBps` = `19.2 MHz` XO floor) (`0009`) while preserving `vermagic` across all 580 `.ko.zst` modules. - **MSM8909 RPM interconnect bus scaling (`CONFIG_INTERCONNECT_QCOM_MSM8909=y`)**: enabled `CONFIG_INTERCONNECT_QCOM=y`, `CONFIG_INTERCONNECT_QCOM_MSM8909=y`, and `CONFIG_INTERCONNECT_QCOM_SMD_RPM=y`, marked `msm8909_bimc`, `msm8909_pcnoc`, and `msm8909_snoc` `.keep_alive = true` (`19.2 MHz` active floor, `0` in `QCOM_SMD_RPM_SLEEP_STATE`), initialized `qp->bus_clk_rate[*]` to `U32_MAX` in `qnoc_probe()` so `icc_sync_state` clears `clk_smd_rpm_handoff()`'s `INT_MAX` sleep-set vote in RPM, wired `interconnect@400000`, `interconnect@500000`, `interconnect@580000`, `cpus` `interconnects`, and `cpu-opp-table` `opp-peak-kBps` across all six MSM8905/MSM8909 DTS files, and lowered the `199999951 Hz` idle CPU OPP `opp-peak-kBps` floor from `<0xc3500>` (`100 MHz` BIMC) to `<0x25800>` (`153,600 kBps` = `19.2 MHz` XO floor) (`0009`) while preserving `vermagic` across all 580 `.ko.zst` modules.
- **Unblock `fw_devlink` `sync_state` (`CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y`) and release unclaimed `clk-smd-rpm` votes (`0009`)**: enabled `CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y` with `fw_devlink` post-init relaxation in `drivers/base/core.c` so driverless `/cpus/cpu@0..3` no longer deadlock `rpmpd_sync_state()` (`VDD_CX`/`VDD_MX` stuck at `SUPER_TURBO`) or `icc_sync_state()`, and added `late_initcall_sync(rpm_smd_clk_late_cleanup)` in `drivers/clk/qcom/clk-smd-rpm.c` to drop active votes on unclaimed `QDSS`/`QPIC` clocks and clear RPM `SLEEP_STATE` boot-handoff votes on all unclaimed clocks without altering `BB_CLK1`/`RF_CLK1` active votes. - **Unblock `fw_devlink` `sync_state` (`CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y`) and release unclaimed `clk-smd-rpm` votes (`0009`)**: enabled `CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y` with `fw_devlink` post-init relaxation in `drivers/base/core.c` so driverless `/cpus/cpu@0..3` no longer deadlock `rpmpd_sync_state()` (`VDD_CX`/`VDD_MX` stuck at `SUPER_TURBO`) or `icc_sync_state()`, and added `late_initcall_sync(rpm_smd_clk_late_cleanup)` in `drivers/clk/qcom/clk-smd-rpm.c` to drop active votes on unclaimed `QDSS`/`QPIC` clocks and clear RPM `SLEEP_STATE` boot-handoff votes on all unclaimed clocks without altering `BB_CLK1`/`RF_CLK1` active votes.
@@ -28,7 +34,7 @@ Upcoming release build (`a1114` / `carbonara` via `scripts/version.sh`) targetin
- **2720 Flip event-driven idle daemons (`nokia-beatles`)**: replaced `bananarchy-lid`'s continuous `20 ms` (`50 Hz`) `poll()` loop, `10 Hz` `/sys/kernel/debug/gpio` full SoC GPIO register dump, and `2 s` `/dev/input` `glob` + `/run/bananarchy/cover.sock` broadcast with `/dev/input` `inotify` watching plus hardware `EV_SW` IRQ sleep (`poll(..., -1)` at `0` steady-state wakeups/s after the `20 ms` edge debounce and one `+2 s` post-transition confirmation check), and synchronized CPU `scaling_governor`, `schedutil/rate_limit_us` (`40000`), and Adreno 304 `governor` directly in `on_transition()`. Replaced `bananarchy-volume-keys`'s `1 s` `poll()` + `2 s` `/dev/input` `glob` loop with `/dev/input` `inotify` + `poll(..., -1)`. - **2720 Flip event-driven idle daemons (`nokia-beatles`)**: replaced `bananarchy-lid`'s continuous `20 ms` (`50 Hz`) `poll()` loop, `10 Hz` `/sys/kernel/debug/gpio` full SoC GPIO register dump, and `2 s` `/dev/input` `glob` + `/run/bananarchy/cover.sock` broadcast with `/dev/input` `inotify` watching plus hardware `EV_SW` IRQ sleep (`poll(..., -1)` at `0` steady-state wakeups/s after the `20 ms` edge debounce and one `+2 s` post-transition confirmation check), and synchronized CPU `scaling_governor`, `schedutil/rate_limit_us` (`40000`), and Adreno 304 `governor` directly in `on_transition()`. Replaced `bananarchy-volume-keys`'s `1 s` `poll()` + `2 s` `/dev/input` `glob` loop with `/dev/input` `inotify` + `poll(..., -1)`.
- **Shared GPU `devfreq`, `schedutil`, statusbar, eMMC, and Bluetooth idle fixes (`nokia-argon` and `nokia-beatles`)**: granted `video`-group `0664` permissions to `/sys/class/devfreq/1c00000.gpu/governor` in `10-power-save.start`, synced `1c00000.gpu/governor` (`powersave` while dark or cover-lit, `simple_ondemand` when the main panel wakes) in `bananarchy-display-power-sync` and `locker.so`, and restored `schedutil/rate_limit_us = 40000` on `FORCE=1` transitions as well as normal udev events. `sxmo_hook_statusbar.sh` skips `sxmo_hook_icons.sh` on `time` ticks and updates `099-time` directly in-shell without spawning `sxmo_status.sh` and duplicate `mkdir -p` forks every minute; `sxmo_wm.sh display off` skips rewriting `~/.config/sxmo/brightness` on ext4 when unchanged; `sxmo_hook_screenoff.sh` skips spawning `sxmo_autosuspend.sh` when `/etc/bananarchy-no-deep-standby` is present; and `bananarchy-bt-obex` replaces its `1.0 s` D-Bus/RFCOMM poll and `1.5-2.0 s` `/dev/input` gamepad scan with a signal self-pipe, `ctypes` `inotify`, and blocking `select.select(..., None)` (`0` idle wakeups/s when Bluetooth is enabled, `<5 ms` gamepad hotplug). - **Shared GPU `devfreq`, `schedutil`, statusbar, eMMC, and Bluetooth idle fixes (`nokia-argon` and `nokia-beatles`)**: granted `video`-group `0664` permissions to `/sys/class/devfreq/1c00000.gpu/governor` in `10-power-save.start`, synced `1c00000.gpu/governor` (`powersave` while dark or cover-lit, `simple_ondemand` when the main panel wakes) in `bananarchy-display-power-sync` and `locker.so`, and restored `schedutil/rate_limit_us = 40000` on `FORCE=1` transitions as well as normal udev events. `sxmo_hook_statusbar.sh` skips `sxmo_hook_icons.sh` on `time` ticks and updates `099-time` directly in-shell without spawning `sxmo_status.sh` and duplicate `mkdir -p` forks every minute; `sxmo_wm.sh display off` skips rewriting `~/.config/sxmo/brightness` on ext4 when unchanged; `sxmo_hook_screenoff.sh` skips spawning `sxmo_autosuspend.sh` when `/etc/bananarchy-no-deep-standby` is present; and `bananarchy-bt-obex` replaces its `1.0 s` D-Bus/RFCOMM poll and `1.5-2.0 s` `/dev/input` gamepad scan with a signal self-pipe, `ctypes` `inotify`, and blocking `select.select(..., None)` (`0` idle wakeups/s when Bluetooth is enabled, `<5 ms` gamepad hotplug).
- **Image persistence and upcoming release archives**: rebuilt both `images/bananarchy-nokia-argon.img` (SHA-256 `f4c8921a674944b2687b2d7bcb52e6f3cb81ad5997fddac969949305c0479c60`) and `images/bananarchy-nokia-beatles.img` (SHA-256 `fd29593b30008b65b7b30b867824ce3f3f4e1f70cda4f012dde1a2c14dd316ba`, with standalone `images/boot-bananarchy-nokia-beatles.img` SHA-256 `d6cb9d5f13bc00815c4fcde5cf32b92ce9d7873683d3cec8b1346a53801ea08a` and unchanged display lk2nd `b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d`) stamped as `a1114` / `carbonara` with `--mkinitfs`, pinned in `scripts/check-rebuild.sh`, and packaged into `bananarchy-nokia-argon-a1114-carbonara.zip` (`a42ae7a6484a35b92580d8b9a6cbc58ba605e99d29cc5a353b423a69aa51febb`) and `bananarchy-nokia-beatles-a1114-carbonara.zip` (`463332fa4aeb78349a608d9a15f27c62dbe736129bdd2291b58f3ff1038a0a9f`). - **Image persistence and upcoming release archives**: rebuilt both `images/bananarchy-nokia-argon.img` (SHA-256 `77a1201a2a93a076a8dd9a6f11c8ceb5f69b94b2ca7abb3dfeba5354b83c034c`) and `images/bananarchy-nokia-beatles.img` (SHA-256 `c027c3151f3cf45e7a067beed77d77ff4a1954ababda6f1a2eba5a02b2414b24`, with standalone `images/boot-bananarchy-nokia-beatles.img` SHA-256 `5a7a391aff3fc8fc95b07b532eedce1ee17991574fb45ca4359c0504aeb82324` and unchanged display lk2nd `b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d`) stamped as `a1114` / `carbonara` with `--mkinitfs`, pinned in `scripts/check-rebuild.sh`, and packaged into `bananarchy-nokia-argon-a1114-carbonara.zip` (`a721506d9fd5d50a4f47afa6dc2d24c8bc2335e39bfd6d0873c6d30f4892a8f7`) and `bananarchy-nokia-beatles-a1114-carbonara.zip` (`5bb987e264b684c2afdb2f6d60c4d47864aa772c763ad7527dc6f3fb51b5eb85`).
--- ---
+4 -4
View File
@@ -109,12 +109,12 @@ sudo dd if=./images/bananarchy-<device>.img of=/dev/sdX bs=4M status=progress co
| **Slider / flip close & open** | `SW_LID` (`lid:on` / `lid:off`) | **Close**: close open menu, turn off main/keypad backlights, and lock phone with passcode (`xlocker`); **Open**: restore screen and keypad backlight and show passcode lock screen | | **Slider / flip close & open** | `SW_LID` (`lid:on` / `lid:off`) | **Close**: close open menu, turn off main/keypad backlights, and lock phone with passcode (`xlocker`); **Open**: restore screen and keypad backlight and show passcode lock screen |
| **2720 Flip outer side keys (closed)** | `KEY_VOLUMEUP` / `KEY_VOLUMEDOWN` / `KEY_POWER` | While the flip is closed, wake the external `240x240` cover display (centered clock, date, battery, and network indicators) for the configured **Screen blank** duration while keeping the internal panel dark | | **2720 Flip outer side keys (closed)** | `KEY_VOLUMEUP` / `KEY_VOLUMEDOWN` / `KEY_POWER` | While the flip is closed, wake the external `240x240` cover display (centered clock, date, battery, and network indicators) for the configured **Screen blank** duration while keeping the internal panel dark |
> **Screen blanking, idle blanking, deep standby, passcode locking (`xlocker`), waking, and brightness persistence**: > **Screen blanking, idle blanking, RPM idle standby, passcode locking (`xlocker`), waking, and brightness persistence**:
> While unlocked (and with the lid open), the display blanks automatically after the configured **Screen blank** timeout — **5 minutes by default** — via `dwm`'s own evdev input timer and `bananarchy-idle-blank.sh`. Change it in **Config -> Screen blank** (`Off`, 30 s, 1/5/10/30 min), which writes `~/.config/sxmo/idle_blank_timeout`; `bananarchy-idle-timeout.sh get|label|set <seconds>` does the same from the shell, and `SXMO_UNLOCK_IDLE_TIME` or `~/.cache/sxmo/sxmo.noidle` still override/disable it. Closing the slider/lid or locking from the **Power** menu blanks the panel **immediately** (both `Lock` and `Lock (Screen off)` now use `xlocker screenoff`), and an incoming call or SMS/notification turns it back on **immediately** via `bananarchy-screen-wake.sh`, which also resets `dwm`'s idle timer so it cannot blank again right away. Any keypad, lid or power key also restores the display; if it arrives before the idle-lock delay elapses, the desktop stays unlocked. Blanking now arms the screenlock daemon: `bananarchy-idle-blank.sh` calls `bananarchy-idle-lock.sh arm`, which starts the trusted `sxmo_state.sh set screenoff` transition (`xlocker screenoff` -> `LOCK_BLANK` on `locker.so`) after **30 seconds** of dark panel by default. Set `~/.config/sxmo/idle_lock_delay` with `bananarchy-idle-lock.sh set 0` to lock immediately on blank, any other number of seconds to change the grace period, or `set off` to keep the old blank-without-passcode behaviour. `bananarchy-idle-lock.sh get|label|cancel` reports and cancels the pending lock; `bananarchy-screen-wake.sh`, `bananarchy-idle-blank.sh on` and `sxmo_hook_unlock.sh` cancel it on every wake, and the transition only fires while the panel is still dark. X11 screensaver timeouts stay at `0 0 0`; DPMS is driven by the backlight state. Optional **deep standby** is currently **unavailable**: the shipped kernel keeps the pmaports module ABI and has no sleep states in `/sys/power/state`. It stays disabled via `/etc/bananarchy-no-deep-standby`. Even a full custom kernel module tree would not help here: this firmware has no PSCI `SYSTEM_SUSPEND`, so only s2idle (`freeze`) would be possible, without DDR self-refresh, and the saving would be under 1 mA (see `BATTERY-OPTIMIZATION-ANALYSIS.md`). Active calls, SSH sessions and VPN/tether connections would block suspension. Locking the phone (`Power -> Lock`, `Power -> Lock (Screen off)`, `2x End / Power`, or closing the physical slider) activates the fullscreen `240x320` **Passcode Locker (`xlocker` / `locker.so`)**, which verifies your numeric system password (`147147` by default, checked against `/etc/shadow` via `/usr/bin/bananarchy-verify-passcode`). While locked, there is no keypad, softkey, slider, or power-button bypass (`dmenu`, `xdrawer`, terminal spawning, and desktop shortcuts are blocked, and only incoming calls can temporarily overlay `xcallscreen`). Screen and keypad brightness levels configured in **XDrawer** or **Config -> Brightness** are persisted in `~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` and restored on every wake. > While unlocked (and with the lid open), the display blanks automatically after the configured **Screen blank** timeout — **5 minutes by default** — via `dwm`'s own evdev input timer and `bananarchy-idle-blank.sh`. Change it in **Config -> Screen blank** (`Off`, 30 s, 1/5/10/30 min), which writes `~/.config/sxmo/idle_blank_timeout`; `bananarchy-idle-timeout.sh get|label|set <seconds>` does the same from the shell, and `SXMO_UNLOCK_IDLE_TIME` or `~/.cache/sxmo/sxmo.noidle` still override/disable it. Closing the slider/lid or locking from the **Power** menu blanks the panel **immediately** (both `Lock` and `Lock (Screen off)` now use `xlocker screenoff`), and an incoming call or SMS/notification turns it back on **immediately** via `bananarchy-screen-wake.sh`, which also resets `dwm`'s idle timer so it cannot blank again right away. Any keypad, lid or power key also restores the display; if it arrives before the idle-lock delay elapses, the desktop stays unlocked. Blanking now arms the screenlock daemon: `bananarchy-idle-blank.sh` calls `bananarchy-idle-lock.sh arm`, which starts the trusted `sxmo_state.sh set screenoff` transition (`xlocker screenoff` -> `LOCK_BLANK` on `locker.so`) after **30 seconds** of dark panel by default. Set `~/.config/sxmo/idle_lock_delay` with `bananarchy-idle-lock.sh set 0` to lock immediately on blank, any other number of seconds to change the grace period, or `set off` to keep the old blank-without-passcode behaviour. `bananarchy-idle-lock.sh get|label|cancel` reports and cancels the pending lock; `bananarchy-screen-wake.sh`, `bananarchy-idle-blank.sh on` and `sxmo_hook_unlock.sh` cancel it on every wake, and the transition only fires while the panel is still dark. X11 screensaver timeouts stay at `0 0 0`; DPMS is driven by the backlight state. Traditional Linux **`mem` suspend (`/sys/power/state`)** stays disabled (`# CONFIG_SUSPEND is not set` + `/etc/bananarchy-no-deep-standby`) to keep the pmaports module ABI and instant hardware wakeups (stock firmware lacks PSCI `SYSTEM_SUSPEND`); instead, `cpuidle_qcom_spm` enters hardware XO/RPM sleep (`vMPM`) and L2 SAW2 retention/collapse (`CPU_RPM_SLEEP=1`, `CPU_L2_SLEEP=1`) directly from deep idle while `serial@78af000` (`console=ttyMSM0`) is disabled so UART clocks never pin XO or `gpll0`. Locking the phone (`Power -> Lock`, `Power -> Lock (Screen off)`, `2x End / Power`, or closing the physical slider) activates the fullscreen `240x320` **Passcode Locker (`xlocker` / `locker.so`)**, which verifies your numeric system password (`147147` by default, checked against `/etc/shadow` via `/usr/bin/bananarchy-verify-passcode`). While locked, there is no keypad, softkey, slider, or power-button bypass (`dmenu`, `xdrawer`, terminal spawning, and desktop shortcuts are blocked, and only incoming calls can temporarily overlay `xcallscreen`). Screen and keypad brightness levels configured in **XDrawer** or **Config -> Brightness** are persisted in `~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` and restored on every wake.
> **Runtime power policy (`/etc/bananarchy-power-policy.conf`)**: > **Runtime power policy (`/etc/bananarchy-power-policy.conf`)**:
> `WIFI_LISTEN_INTERVAL` (1-10, default 5) sets the `wcn36xx` beacon listen interval (`max_listen_interval` and `conf.listen_interval`) via `/etc/modprobe.d/10-bananarchy-power.conf`, while `bananarchy-display-power-sync` toggles `/sys/module/wcn36xx/parameters/screen_off_offload` to enable WCN3620 ARP/IPv6-NS/GTK and DTIM offloads while the main panel is dark without suspending host RX. `MODEM_DRX_MODE` (default `6`) applies the Qualcomm `AT$QCDRX` DRX mode across all `/dev/wwan0at*` channels at boot and on screen transitions (cached per AT port inode); `6` enables the standard ~1.28 s low-power paging cycle across active SIMs, `7-9` are progressively longer undocumented paging cycles, and `0` leaves the firmware default untouched. The standard `AT+CPSMS` / `AT+CEDRXS` PSM/eDRX commands are not supported by this modem firmware. `DSDS_SECONDARY_MODE=eco` (default `active`) deactivates the secondary SIM's GW provisioning session after `DSDS_PARK_DELAY` seconds (default 300) of a dark panel and restores it on wake; **SIM2 is unreachable while parked**. This uses QMI provisioning sessions, not SIM power-off, so a PIN-locked SIM stays locked. Edit the file as root and run `doas /usr/bin/bananarchy-power-policy.sh apply`, or reboot; `doas /usr/bin/bananarchy-power-policy.sh status` reports the effective values across all AT ports and `wcn36xx`. DDR self-refresh / `mem` suspend is unavailable on this firmware (no PSCI `SYSTEM_SUSPEND`); see `BATTERY-OPTIMIZATION-ANALYSIS.md` §§15, 20. > `WIFI_LISTEN_INTERVAL` (1-10, default 5) sets the `wcn36xx` beacon listen interval (`max_listen_interval` and `conf.listen_interval`) via `/etc/modprobe.d/10-bananarchy-power.conf`, while `bananarchy-display-power-sync` toggles `/sys/module/wcn36xx/parameters/screen_off_offload` to enable WCN3620 ARP/IPv6-NS/GTK, BET, and DTIM offloads (`HOST_SUSPEND_IND`) while the main panel is dark without suspending host RX. `WIFI_SCREEN_OFF_IPV6_MUTE=1` (default) mutes unsolicited IPv6 router advertisements (`accept_ra=0`) on `wlan0` while dark if `wlan0` already holds an IPv4 address and restores the previous value on wake. `WIFI_STANDBY_RAT=keep` (default; set `gsm` to opt in) optionally parks QMI NAS mode preference to GSM after 30 s of darkness while `wlan0` is `up`, restoring the saved RAT preference on wake. `CPU_RPM_SLEEP=1` and `CPU_L2_SLEEP=1` (both default `1`) control runtime `/sys/module/cpuidle_qcom_spm/parameters/{rpm_sleep,l2_sleep}` cluster RPM (`vMPM`) and L2 SAW2 sleep handoff when all online CPUs go idle. `MODEM_DRX_MODE` (default `6`) applies the Qualcomm `AT$QCDRX` DRX mode across all `/dev/wwan0at*` channels at boot and on screen transitions (cached per AT port inode); `6` enables the standard ~1.28 s low-power paging cycle across active SIMs, `7-9` are progressively longer undocumented paging cycles, and `0` leaves the firmware default untouched. The standard `AT+CPSMS` / `AT+CEDRXS` PSM/eDRX commands are not supported by this modem firmware. `DSDS_SECONDARY_MODE=eco` (default `active`) deactivates the secondary SIM's GW provisioning session after `DSDS_PARK_DELAY` seconds (default 300) of a dark panel and restores it on wake; **SIM2 is unreachable while parked**. This uses QMI provisioning sessions, not SIM power-off, so a PIN-locked SIM stays locked. Edit the file as root and run `doas /usr/bin/bananarchy-power-policy.sh apply`, or reboot; `doas /usr/bin/bananarchy-power-policy.sh status` reports the effective values across AT ports, `wcn36xx`, `cpuidle_qcom_spm`, `/sys/kernel/debug/qcom_stats`, and `/sys/kernel/debug/qcom_rpm_master_stats`. See `BATTERY-OPTIMIZATION-ANALYSIS.md` §§15, 20-22.
#### 3.1.1 Window tiling modes and switching combos #### 3.1.1 Window tiling modes and switching combos
By default, `dwm` uses the **vertical bottom-stack (`bstack`, `TTT`)** layout so multiple `st` terminals stack **vertically (one under another)** to preserve full line width on the `240x320` portrait screen. By default, `dwm` uses the **vertical bottom-stack (`bstack`, `TTT`)** layout so multiple `st` terminals stack **vertically (one under another)** to preserve full line width on the `240x320` portrait screen.
@@ -514,7 +514,7 @@ The `msm8905-cam` kernel module drives the rear 2MP GalaxyCore `GC2395` (TA-1048
### 5.2 Audio routing, music playback, and microphone recording ### 5.2 Audio routing, music playback, and microphone recording
Both the rear loudspeaker (`Speaker`, with boosted `RX3 Digital Volume` for loud, clear ringtones and media), the front earpiece speaker (`Earpiece`, boosted by +6 dB and selectable as a standard output device for any audio stream), and wired 3.5mm headphones (`Headphones`, automatically detected and routed on plug-in and restored to `Speaker` on unplug by `sxmo_soundmonitor.sh`), as well as the internal MEMS microphone (`Mic1`) and 3.5mm headset microphone (`Mic2`), are managed through PipeWire/WirePlumber and `sxmo_audio.sh` with linear `1%`–`100%` volume controls across all channels: Both the rear loudspeaker (`Speaker`, with boosted `RX3 Digital Volume` for loud, clear ringtones and media), the front earpiece speaker (`Earpiece`, boosted by +6 dB and selectable as a standard output device for any audio stream), and wired 3.5mm headphones (`Headphones`, automatically detected and routed on plug-in and restored to `Speaker` on unplug by `bananarchy-soundmonitor`), as well as the internal MEMS microphone (`Mic1`) and 3.5mm headset microphone (`Mic2`), are managed through PipeWire/WirePlumber and `sxmo_audio.sh` with linear `1%`–`100%` volume controls across all channels:
- **Open an audio file, tracker module (`.mod`, `.xm`, `.it`, `.s3m`), monophonic ringtone (`.nrt`, `.rtttl`, `.rtx`, `.emy`, `.imy`), or folder in the native music player (`xmusic`)**: - **Open an audio file, tracker module (`.mod`, `.xm`, `.it`, `.s3m`), monophonic ringtone (`.nrt`, `.rtttl`, `.rtx`, `.emy`, `.imy`), or folder in the native music player (`xmusic`)**:
```bash ```bash
+2 -2
View File
@@ -107,7 +107,7 @@ bananarchy/
│ ├── xf86-video-fbdev/ # Xlibre xf86-video-fbdev fallback DDX driver │ ├── xf86-video-fbdev/ # Xlibre xf86-video-fbdev fallback DDX driver
│ ├── fcitx5-t9/ # 6-mode fcitx5-t9 keypad input method │ ├── fcitx5-t9/ # 6-mode fcitx5-t9 keypad input method
│ ├── games/ # Standalone keypad X11 games, Gambatte GB/GBC, and ReMEdy J2ME (snake, tetris, scoundrel, gambatte, remedy) │ ├── games/ # Standalone keypad X11 games, Gambatte GB/GBC, and ReMEdy J2ME (snake, tetris, scoundrel, gambatte, remedy)
│ ├── bananarchy-daemons/ # Compiled 2720 Flip lid, cover-display, and outer volume-key C daemons │ ├── bananarchy-daemons/ # Compiled ARM ELF idle and autostart C daemons (`lid`, `cover-idle`, `volume-keys`, `dsds`, monitors, session)
│ ├── leds-msm8905-torch/ # Kernel driver for SY7807 torch LED, WCD codec init, and PON shutdown │ ├── leds-msm8905-torch/ # Kernel driver for SY7807 torch LED, WCD codec init, and PON shutdown
│ └── msm8905-cam/ # Kernel V4L2 driver for GC2395/GC2385/GC2365 2MP rear camera (/dev/video0) │ └── msm8905-cam/ # Kernel V4L2 driver for GC2395/GC2385/GC2365 2MP rear camera (/dev/video0)
├── overlay/rootfs/ # System configuration overlay applied over the target rootfs ├── overlay/rootfs/ # System configuration overlay applied over the target rootfs
@@ -171,7 +171,7 @@ All components are pre-compiled in `prebuilt/` and `overlay/rootfs/`, and can be
# Rebuild Linux 6.12.1-msm8916 Adreno 304 DRM/MSM GPU module, QDSP6/Q6Voice audio modules, torch LED module, camera module, and DTBs # Rebuild Linux 6.12.1-msm8916 Adreno 304 DRM/MSM GPU module, QDSP6/Q6Voice audio modules, torch LED module, camera module, and DTBs
./scripts/build-kernel-audio.sh ./scripts/build-kernel-audio.sh
# Rebuild 2720 Flip idle daemons (bananarchy-lid, bananarchy-cover-idle, bananarchy-volume-keys) and display lk2nd # Rebuild compiled C idle/autostart daemons (`bananarchy-*`) and display lk2nd
./scripts/build-bananarchy-daemons.sh ./scripts/build-bananarchy-daemons.sh
./scripts/build-lk2nd-beatles.sh ./scripts/build-lk2nd-beatles.sh
``` ```
+1 -1
View File
@@ -56,7 +56,7 @@ nonfree_firmware() {
sha512sums=" sha512sums="
66302bb5d83c4ba155ff62405fb9a374ab76e1912411310b1ad75e00c216b6868da4e2b6f3987c97146389aa44b2b2c26f0ca0819566be45c9d0d2dd1d3b72f1 00-nokia-argon-display.files 66302bb5d83c4ba155ff62405fb9a374ab76e1912411310b1ad75e00c216b6868da4e2b6f3987c97146389aa44b2b2c26f0ca0819566be45c9d0d2dd1d3b72f1 00-nokia-argon-display.files
ef4587f749b941761cb7838d9e21e0bd9436693a4a8bd38ac5d7cae6e9ceb2c1e7358d5fe9a34b23d6ff484c81079533eaee6c3e609d8bc685902ff150e1e79d deviceinfo ef4587f749b941761cb7838d9e21e0bd9436693a4a8bd38ac5d7cae6e9ceb2c1e7358d5fe9a34b23d6ff484c81079533eaee6c3e609d8bc685902ff150e1e79d deviceinfo
37e1e5f8839b624ab3eb850a24ed4daeb61a651257a1fb593f49cb869323e5d1b339c831a18eb26a9d7bd0a618ea9eb2bb9bf3882133af5f2606a878e6d39c67 kernel-cmdline.conf cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e kernel-cmdline.conf
749fa5911f53f65c1a18a8768d374d1ea39ef47ed61146a5f79d669250788501434a059cfff65b83cb54eb7273841686b4a3a04f20aaec6ec7f742e14623c8bc modules-initfs 749fa5911f53f65c1a18a8768d374d1ea39ef47ed61146a5f79d669250788501434a059cfff65b83cb54eb7273841686b4a3a04f20aaec6ec7f742e14623c8bc modules-initfs
dd82fd4732694a24c91339b5c5fbb0bf485b3b2da3c17c11b72a02e90e9827c367504c99894556dd8273f927408cdb187325e5f3b9ea9e4a82e3cb3798cb2816 nokia,argon-gc9305-v2-panel.txt dd82fd4732694a24c91339b5c5fbb0bf485b3b2da3c17c11b72a02e90e9827c367504c99894556dd8273f927408cdb187325e5f3b9ea9e4a82e3cb3798cb2816 nokia,argon-gc9305-v2-panel.txt
" "
-1
View File
@@ -1 +0,0 @@
console=ttyMSM0,115200
Binary file not shown.
@@ -15,7 +15,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -114,6 +113,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -616,14 +616,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -671,6 +708,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1100,6 +1138,8 @@
power-domains = <0x14 1>; power-domains = <0x14 1>;
operating-points-v2 = <&gpu_opp_table>; operating-points-v2 = <&gpu_opp_table>;
iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <2>; #cooling-cells = <2>;
gpu_opp_table: opp-table { gpu_opp_table: opp-table {
@@ -1694,7 +1734,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x53>; pinctrl-0 = <0x53>;
pinctrl-1 = <0x54>; pinctrl-1 = <0x54>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -2133,6 +2173,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2373,4 +2419,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -18,7 +18,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -117,6 +116,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -617,14 +617,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -672,6 +709,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1121,6 +1159,8 @@
power-domains = <0x14 0x01>; power-domains = <0x14 0x01>;
operating-points-v2 = <0x8b>; operating-points-v2 = <0x8b>;
iommus = <0x8c 0x01 0x8c 0x02>; iommus = <0x8c 0x01 0x8c 0x02>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <0x02>; #cooling-cells = <0x02>;
opp-table { opp-table {
@@ -1720,7 +1760,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x53>; pinctrl-0 = <0x53>;
pinctrl-1 = <0x54>; pinctrl-1 = <0x54>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -2209,6 +2249,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2460,4 +2506,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
Binary file not shown.
@@ -18,7 +18,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -117,6 +116,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -617,14 +617,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -672,6 +709,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1109,6 +1147,8 @@
power-domains = <0x14 0x01>; power-domains = <0x14 0x01>;
operating-points-v2 = <0x8b>; operating-points-v2 = <0x8b>;
iommus = <0x8c 0x01 0x8c 0x02>; iommus = <0x8c 0x01 0x8c 0x02>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <0x02>; #cooling-cells = <0x02>;
opp-table { opp-table {
@@ -1708,7 +1748,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x53>; pinctrl-0 = <0x53>;
pinctrl-1 = <0x54>; pinctrl-1 = <0x54>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -2155,6 +2195,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2396,4 +2442,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
+1 -1
View File
@@ -57,6 +57,6 @@ sha512sums="
721d740ff8dbbbafff4bc734228a82bd57d76177b9bf417d660ecb181a72a998319ddbde77d0efc5e875d2256596578212e3e0bfb85c2e77e5bbf6d0e88d9fa4 nokia,sparkler-gc9307-hlt-28-panel.txt 721d740ff8dbbbafff4bc734228a82bd57d76177b9bf417d660ecb181a72a998319ddbde77d0efc5e875d2256596578212e3e0bfb85c2e77e5bbf6d0e88d9fa4 nokia,sparkler-gc9307-hlt-28-panel.txt
89b3dd5bf1dd5e85bf66bfb6dba56e2a8e919fe3aa7dc369c18c9e56f7e0ae88319186551412497a601081b904c12dd07ebed4f39fd4a4ba6199fb8af9c90f40 00-nokia-sparkler-display.files 89b3dd5bf1dd5e85bf66bfb6dba56e2a8e919fe3aa7dc369c18c9e56f7e0ae88319186551412497a601081b904c12dd07ebed4f39fd4a4ba6199fb8af9c90f40 00-nokia-sparkler-display.files
5df56915a719654bd6d23b127c2d55b0445e731a0d1648c1c48188b0f84e62d1f83f34f2dbfe5e2c694525579cbe438e3a5b66cece6047b53dc9a2995a6fbfb2 deviceinfo 5df56915a719654bd6d23b127c2d55b0445e731a0d1648c1c48188b0f84e62d1f83f34f2dbfe5e2c694525579cbe438e3a5b66cece6047b53dc9a2995a6fbfb2 deviceinfo
37e1e5f8839b624ab3eb850a24ed4daeb61a651257a1fb593f49cb869323e5d1b339c831a18eb26a9d7bd0a618ea9eb2bb9bf3882133af5f2606a878e6d39c67 kernel-cmdline.conf cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e kernel-cmdline.conf
d5dfe844a45cfc4e0844e43b8fb3e1bbcb155e06430188f8d5059fc5ce3c4100fde7f1580b1b54c5318f40d238736b233463582e55b9dd25654e40539e11ed39 modules-initfs d5dfe844a45cfc4e0844e43b8fb3e1bbcb155e06430188f8d5059fc5ce3c4100fde7f1580b1b54c5318f40d238736b233463582e55b9dd25654e40539e11ed39 modules-initfs
" "
+1 -1
View File
@@ -57,6 +57,6 @@ sha512sums="
8583c7d5a97c4efedff3ec554cf682d815fd7b83140c2cab9eec4b6e2e735ce3c012bc3bd97f8bc75adc3483f76ce83a5bf1090d4f3e73a327efc64ca9eca5a7 nokia,leo-gc9305-hlt-24-panel.txt 8583c7d5a97c4efedff3ec554cf682d815fd7b83140c2cab9eec4b6e2e735ce3c012bc3bd97f8bc75adc3483f76ce83a5bf1090d4f3e73a327efc64ca9eca5a7 nokia,leo-gc9305-hlt-24-panel.txt
c9985232e5e64ddb0906b053e5024c87fa62cc1bcb254260e1ef6afb43d384196e09d41287143bcba61dff616dd6b562a5ca335dbe592fcd8c954642b8085f38 00-nokia-leo-display.files c9985232e5e64ddb0906b053e5024c87fa62cc1bcb254260e1ef6afb43d384196e09d41287143bcba61dff616dd6b562a5ca335dbe592fcd8c954642b8085f38 00-nokia-leo-display.files
34c6269610e41b51b31b293cc3777a2af1776375617aecf001347e8d7e05a13b8bcf4ce82e13938a219493d780003631076dbd2f3f6fd26c249ec96b1b36219e deviceinfo 34c6269610e41b51b31b293cc3777a2af1776375617aecf001347e8d7e05a13b8bcf4ce82e13938a219493d780003631076dbd2f3f6fd26c249ec96b1b36219e deviceinfo
37e1e5f8839b624ab3eb850a24ed4daeb61a651257a1fb593f49cb869323e5d1b339c831a18eb26a9d7bd0a618ea9eb2bb9bf3882133af5f2606a878e6d39c67 kernel-cmdline.conf cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e kernel-cmdline.conf
d5dfe844a45cfc4e0844e43b8fb3e1bbcb155e06430188f8d5059fc5ce3c4100fde7f1580b1b54c5318f40d238736b233463582e55b9dd25654e40539e11ed39 modules-initfs d5dfe844a45cfc4e0844e43b8fb3e1bbcb155e06430188f8d5059fc5ce3c4100fde7f1580b1b54c5318f40d238736b233463582e55b9dd25654e40539e11ed39 modules-initfs
" "
@@ -1 +0,0 @@
console=ttyMSM0,115200
Binary file not shown.
@@ -15,7 +15,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -114,6 +113,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -620,14 +620,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -675,6 +712,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1077,6 +1115,8 @@
power-domains = <0x14 1>; power-domains = <0x14 1>;
operating-points-v2 = <&gpu_opp_table>; operating-points-v2 = <&gpu_opp_table>;
iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <2>; #cooling-cells = <2>;
gpu_opp_table: opp-table { gpu_opp_table: opp-table {
@@ -1388,7 +1428,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x47>; pinctrl-0 = <0x47>;
pinctrl-1 = <0x48>; pinctrl-1 = <0x48>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -1828,6 +1868,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2048,4 +2094,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
@@ -15,7 +15,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -114,6 +113,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -620,14 +620,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -675,6 +712,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1077,6 +1115,8 @@
power-domains = <0x14 1>; power-domains = <0x14 1>;
operating-points-v2 = <&gpu_opp_table>; operating-points-v2 = <&gpu_opp_table>;
iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <2>; #cooling-cells = <2>;
gpu_opp_table: opp-table { gpu_opp_table: opp-table {
@@ -1388,7 +1428,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x47>; pinctrl-0 = <0x47>;
pinctrl-1 = <0x48>; pinctrl-1 = <0x48>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -1828,6 +1868,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2048,4 +2094,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
-1
View File
@@ -1 +0,0 @@
console=ttyMSM0,115200
Binary file not shown.
@@ -15,7 +15,6 @@
}; };
chosen { chosen {
stdout-path = "serial0";
}; };
clocks { clocks {
@@ -114,6 +113,7 @@
l2-cache { l2-cache {
compatible = "cache"; compatible = "cache";
cache-level = <0x02>; cache-level = <0x02>;
qcom,saw = <0xb5>;
phandle = <0x02>; phandle = <0x02>;
}; };
@@ -616,14 +616,51 @@
sram@60000 { sram@60000 {
compatible = "qcom,rpm-msg-ram"; compatible = "qcom,rpm-msg-ram";
reg = <0x60000 0x8000>; reg = <0x60000 0x8000>;
#address-cells = <0x01>;
#size-cells = <0x01>;
ranges = <0x00 0x60000 0x8000>;
phandle = <0x17>; phandle = <0x17>;
sram@150 {
reg = <0x150 0x50>;
phandle = <0xb0>;
};
sram@1d0 {
reg = <0x1d0 0x40>;
phandle = <0xb1>;
};
sram@1150 {
reg = <0x1150 0x50>;
phandle = <0xb2>;
};
sram@2150 {
reg = <0x2150 0x50>;
phandle = <0xb3>;
};
}; };
sram@290000 { sram@290000 {
compatible = "qcom,rpm-stats"; compatible = "qcom,msm8916-rpm-stats";
reg = <0x290000 0x10000>; reg = <0x290000 0x10000>;
}; };
interrupt-controller@601d0 {
compatible = "qcom,mpm";
qcom,rpm-msg-ram = <0xb1>;
interrupts = <0x00 0xab 0x01>;
mboxes = <0x03 0x01>;
interrupt-controller;
#interrupt-cells = <0x02>;
#power-domain-cells = <0x00>;
interrupt-parent = <0x01>;
qcom,mpm-pin-count = <0x40>;
qcom,mpm-pin-map = <0x02 0xb8 0x30 0x88 0x31 0x8c 0x35 0x48 0x3a 0x86 0x3e 0xbe>;
phandle = <0xb4>;
};
interconnect@400000 { interconnect@400000 {
compatible = "qcom,msm8909-bimc"; compatible = "qcom,msm8909-bimc";
reg = <0x400000 0x62000>; reg = <0x400000 0x62000>;
@@ -671,6 +708,7 @@
gpio-ranges = <0x27 0x00 0x00 0x75>; gpio-ranges = <0x27 0x00 0x00 0x75>;
interrupt-controller; interrupt-controller;
#interrupt-cells = <0x02>; #interrupt-cells = <0x02>;
wakeup-parent = <0xb4>;
phandle = <0x27>; phandle = <0x27>;
blsp-i2c1-default-state { blsp-i2c1-default-state {
@@ -1100,6 +1138,8 @@
power-domains = <0x14 1>; power-domains = <0x14 1>;
operating-points-v2 = <&gpu_opp_table>; operating-points-v2 = <&gpu_opp_table>;
iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>;
interconnects = <0xa0 0x01 0xa0 0x06>;
interconnect-names = "gfx-mem";
#cooling-cells = <2>; #cooling-cells = <2>;
gpu_opp_table: opp-table { gpu_opp_table: opp-table {
@@ -1694,7 +1734,7 @@
pinctrl-names = "default", "sleep"; pinctrl-names = "default", "sleep";
pinctrl-0 = <0x53>; pinctrl-0 = <0x53>;
pinctrl-1 = <0x54>; pinctrl-1 = <0x54>;
status = "okay"; status = "disabled";
}; };
serial@78b0000 { serial@78b0000 {
@@ -2133,6 +2173,12 @@
}; };
}; };
power-manager@b012000 {
compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2";
reg = <0xb012000 0x1000>;
phandle = <0xb5>;
};
power-manager@b088000 { power-manager@b088000 {
compatible = "qcom,msm8909-acc"; compatible = "qcom,msm8909-acc";
reg = <0xb088000 0x1000>; reg = <0xb088000 0x1000>;
@@ -2373,4 +2419,10 @@
gpios = <0x2c 0x01 0x00>; gpios = <0x2c 0x01 0x00>;
}; };
}; };
rpm-master-stats {
compatible = "qcom,rpm-master-stats";
qcom,rpm-msg-ram = <0xb0 0xb2 0xb3>;
qcom,master-names = "APSS", "MPSS", "PRONTO";
};
}; };
+46619 -46575
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -5256,7 +5256,7 @@ CONFIG_QCOM_PDR_MSG=m
CONFIG_QCOM_QMI_HELPERS=y CONFIG_QCOM_QMI_HELPERS=y
# CONFIG_QCOM_RAMP_CTRL is not set # CONFIG_QCOM_RAMP_CTRL is not set
CONFIG_QCOM_RMTFS_MEM=y CONFIG_QCOM_RMTFS_MEM=y
# CONFIG_QCOM_RPM_MASTER_STATS is not set CONFIG_QCOM_RPM_MASTER_STATS=y
# CONFIG_QCOM_RPMH is not set # CONFIG_QCOM_RPMH is not set
CONFIG_QCOM_SMEM=y CONFIG_QCOM_SMEM=y
CONFIG_QCOM_SMD_RPM=y CONFIG_QCOM_SMD_RPM=y
Binary file not shown.
Binary file not shown.
@@ -22,3 +22,19 @@ MODEM_DRX_MODE=6
# sessions, not SIM power-off, so a PIN-locked SIM stays locked. # sessions, not SIM power-off, so a PIN-locked SIM stays locked.
DSDS_SECONDARY_MODE=active DSDS_SECONDARY_MODE=active
DSDS_PARK_DELAY=300 DSDS_PARK_DELAY=300
# Last-man APSS RPM/vMPM sleep handoff in cpuidle_qcom_spm (1 = enable).
# Lets the fourth/last idle CPU signal RPM so XO/DDR/MX/CX can enter sleep.
CPU_RPM_SLEEP=1
# Last-man L2 SAW2 retention / HSFS_OPEN state in cpuidle_qcom_spm (1 = enable).
CPU_L2_SLEEP=1
# Mute unsolicited IPv6 router advertisements on wlan0 while the screen is off
# when wlan0 already holds an IPv4 address (1 = enable, restored on wake).
WIFI_SCREEN_OFF_IPV6_MUTE=1
# Opt-in modem RAT parking while the screen is off and wlan0 is up:
# keep = keep current RAT preference (default)
# gsm = park NAS mode preference to GSM after 30 s dark on Wi-Fi, restore on wake
WIFI_STANDBY_RAT=keep
+2
View File
@@ -26,6 +26,8 @@ permit nopass :wheel as root cmd systemctl args stop ModemManager
permit nopass :wheel as root cmd systemctl args restart ModemManager permit nopass :wheel as root cmd systemctl args restart ModemManager
permit nopass :wheel as root cmd /usr/libexec/msm-modem-uim-selection permit nopass :wheel as root cmd /usr/libexec/msm-modem-uim-selection
permit nopass :wheel as root cmd msm-modem-uim-selection permit nopass :wheel as root cmd msm-modem-uim-selection
permit nopass :wheel as root cmd /usr/bin/bananarchy-dsds
permit nopass :wheel as root cmd bananarchy-dsds
permit nopass :wheel as root cmd setup-timezone permit nopass :wheel as root cmd setup-timezone
permit nopass :wheel as root cmd /sbin/setup-timezone permit nopass :wheel as root cmd /sbin/setup-timezone
permit nopass :wheel as root cmd /usr/sbin/setup-timezone permit nopass :wheel as root cmd /usr/sbin/setup-timezone
@@ -53,6 +53,10 @@ if [ -e /sys/class/devfreq/1c00000.gpu/governor ]; then
chgrp video /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true chgrp video /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true
chmod 0664 /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true chmod 0664 /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true
fi fi
if [ -e /sys/module/cpuidle_qcom_spm/parameters/screen_off ]; then
chgrp video /sys/module/cpuidle_qcom_spm/parameters/screen_off 2>/dev/null || true
chmod 0664 /sys/module/cpuidle_qcom_spm/parameters/screen_off 2>/dev/null || true
fi
# Ensure rootfs pm8916_lbc and pm8916_bms_vm modules are active if initramfs loaded an older build # Ensure rootfs pm8916_lbc and pm8916_bms_vm modules are active if initramfs loaded an older build
if [ -r /sys/class/power_supply/pm8916-lbc-chgr/constant_charge_current ]; then if [ -r /sys/class/power_supply/pm8916-lbc-chgr/constant_charge_current ]; then
@@ -16,6 +16,7 @@ KBD_PATH=/sys/class/leds/white:kbd_backlight/brightness
RL_PATH=/sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us RL_PATH=/sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us
GPU_GOV_PATH=/sys/class/devfreq/1c00000.gpu/governor GPU_GOV_PATH=/sys/class/devfreq/1c00000.gpu/governor
WIFI_OFFLOAD_PATH=/sys/module/wcn36xx/parameters/screen_off_offload WIFI_OFFLOAD_PATH=/sys/module/wcn36xx/parameters/screen_off_offload
SPM_SCREEN_OFF_PATH=/sys/module/cpuidle_qcom_spm/parameters/screen_off
COVER_MARKER=/run/bananarchy/cover-backlight COVER_MARKER=/run/bananarchy/cover-backlight
FORCE_MARKER=/run/bananarchy/cover-bl-force FORCE_MARKER=/run/bananarchy/cover-bl-force
STATE_CACHE=/run/bananarchy/cover-power-state STATE_CACHE=/run/bananarchy/cover-power-state
@@ -86,7 +87,9 @@ if [ "$(read_value "$LID_PROFILE")" != "flip" ]; then
[ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "powersave" [ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "powersave"
[ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "Y" [ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "Y"
force_dpms "Off" force_dpms "Off"
[ -w "$SPM_SCREEN_OFF_PATH" ] && set_if_changed "$SPM_SCREEN_OFF_PATH" "Y"
else else
[ -w "$SPM_SCREEN_OFF_PATH" ] && set_if_changed "$SPM_SCREEN_OFF_PATH" "N"
[ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "simple_ondemand" [ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "simple_ondemand"
[ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "N" [ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "N"
force_dpms "On" force_dpms "On"
@@ -180,14 +183,23 @@ else
fi fi
[ -n "$DESIRED_KBD" ] && set_if_changed "$KBD_PATH" "$DESIRED_KBD" [ -n "$DESIRED_KBD" ] && set_if_changed "$KBD_PATH" "$DESIRED_KBD"
if [ "$DESIRED_DPMS" = "Off" ] || [ "$marker" = "0" ] || [ "$marker" = "1" ]; then if [ "$DESIRED_DPMS" = "Off" ]; then
[ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "powersave" [ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "powersave"
[ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "Y"
else else
[ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "simple_ondemand" [ -w "$GPU_GOV_PATH" ] && set_if_changed "$GPU_GOV_PATH" "simple_ondemand"
fi
if [ "$DESIRED_DPMS" = "Off" ] || [ "$marker" = "0" ] || [ "$marker" = "1" ]; then
[ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "Y"
else
[ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "N" [ -w "$WIFI_OFFLOAD_PATH" ] && set_if_changed "$WIFI_OFFLOAD_PATH" "N"
fi fi
if [ "$DESIRED_DPMS" != "Off" ]; then
[ -w "$SPM_SCREEN_OFF_PATH" ] && set_if_changed "$SPM_SCREEN_OFF_PATH" "N"
fi
force_dpms "$DESIRED_DPMS" force_dpms "$DESIRED_DPMS"
if [ "$DESIRED_DPMS" = "Off" ]; then
[ -w "$SPM_SCREEN_OFF_PATH" ] && set_if_changed "$SPM_SCREEN_OFF_PATH" "Y"
fi
[ -w "$RL_PATH" ] && set_if_changed "$RL_PATH" "40000" [ -w "$RL_PATH" ] && set_if_changed "$RL_PATH" "40000"
if [ "$FORCE" -eq 1 ]; then if [ "$FORCE" -eq 1 ]; then
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,9 +10,15 @@ PARKED="$RUNDIR/parked"
AIDFILE="$RUNDIR/secondary.aid" AIDFILE="$RUNDIR/secondary.aid"
SLOTFILE="$RUNDIR/secondary.slot" SLOTFILE="$RUNDIR/secondary.slot"
TOKEN="$RUNDIR/token" TOKEN="$RUNDIR/token"
RAT_PARKED="$RUNDIR/rat_parked"
RAT_SAVED="$RUNDIR/saved_rat"
RAT_TOKEN="$RUNDIR/rat.token"
IPV6_RA_SAVED="$RUNDIR/wlan0_accept_ra"
BOOTTOKEN="$RUNDIR/boot.token" BOOTTOKEN="$RUNDIR/boot.token"
READYSTAMP="$RUNDIR/modem_ready.stamp" READYSTAMP="$RUNDIR/modem_ready.stamp"
DRXLOCK="$RUNDIR/lock.drx" DRXLOCK="$RUNDIR/lock.drx"
ACCEPT_RA=/proc/sys/net/ipv6/conf/wlan0/accept_ra
SPM_PARAM_DIR=/sys/module/cpuidle_qcom_spm/parameters
QMI="timeout 8 qmicli --silent -pd qrtr://0" QMI="timeout 8 qmicli --silent -pd qrtr://0"
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
@@ -23,6 +29,10 @@ WIFI_LISTEN_INTERVAL=5
MODEM_DRX_MODE=6 MODEM_DRX_MODE=6
DSDS_SECONDARY_MODE=active DSDS_SECONDARY_MODE=active
DSDS_PARK_DELAY=300 DSDS_PARK_DELAY=300
CPU_RPM_SLEEP=1
CPU_L2_SLEEP=1
WIFI_SCREEN_OFF_IPV6_MUTE=1
WIFI_STANDBY_RAT=keep
[ -r "$CONF" ] && . "$CONF" [ -r "$CONF" ] && . "$CONF"
mkdir -p "$RUNDIR" 2>/dev/null || true mkdir -p "$RUNDIR" 2>/dev/null || true
@@ -153,8 +163,95 @@ unpark() {
rm -f "$PARKED" "$AIDFILE" "$SLOTFILE" "$RUNDIR"/drx.wwan* 2>/dev/null || true rm -f "$PARKED" "$AIDFILE" "$SLOTFILE" "$RUNDIR"/drx.wwan* 2>/dev/null || true
} }
set_spm_bool() {
path="$1"
val="$2"
[ -w "$path" ] || return 0
case "$val" in
1|Y|y) want="Y" ;;
0|N|n) want="N" ;;
*) return 0 ;;
esac
printf '%s\n' "$want" > "$path" 2>/dev/null || true
}
apply_cpu_lpm() {
set_spm_bool "$SPM_PARAM_DIR/rpm_sleep" "$CPU_RPM_SLEEP"
set_spm_bool "$SPM_PARAM_DIR/l2_sleep" "$CPU_L2_SLEEP"
}
mute_wifi_ipv6_ra() {
[ "$WIFI_SCREEN_OFF_IPV6_MUTE" = "1" ] || return 0
[ -w "$ACCEPT_RA" ] || return 0
ip -4 addr show dev wlan0 2>/dev/null | grep -q 'inet ' || return 0
if [ ! -f "$IPV6_RA_SAVED" ]; then
cur_ra=""
IFS= read -r cur_ra < "$ACCEPT_RA" 2>/dev/null || cur_ra=""
case "$cur_ra" in ''|*[!0-9]*) cur_ra=1 ;; esac
printf '%s\n' "$cur_ra" > "$IPV6_RA_SAVED" 2>/dev/null || true
fi
printf '0\n' > "$ACCEPT_RA" 2>/dev/null || true
}
restore_wifi_ipv6_ra() {
[ -f "$IPV6_RA_SAVED" ] || return 0
saved_ra=1
IFS= read -r saved_ra < "$IPV6_RA_SAVED" 2>/dev/null || saved_ra=1
case "$saved_ra" in ''|*[!0-9]*) saved_ra=1 ;; esac
[ -w "$ACCEPT_RA" ] && printf '%s\n' "$saved_ra" > "$ACCEPT_RA" 2>/dev/null || true
rm -f "$IPV6_RA_SAVED" 2>/dev/null || true
}
park_wifi_rat() {
[ "$WIFI_STANDBY_RAT" = "gsm" ] || return 0
[ -f "$RAT_PARKED" ] && return 0
oper=""
[ -r /sys/class/net/wlan0/operstate ] && { IFS= read -r oper < /sys/class/net/wlan0/operstate 2>/dev/null || oper=""; }
[ "$oper" = "up" ] || return 0
saved_rat="$($QMI --nas-get-system-selection-preference 2>/dev/null | awk -F"'" '
/Mode preference:/ { gsub(/[[:space:]]*,[[:space:]]*/, "|", $2); print $2; exit }
')"
[ -n "$saved_rat" ] || saved_rat="gsm|umts|lte"
[ "$saved_rat" = "gsm" ] && return 0
printf '%s\n' "$saved_rat" > "$RAT_SAVED" 2>/dev/null || true
if $QMI --nas-set-system-selection-preference='gsm' >/dev/null 2>&1; then
: > "$RAT_PARKED"
log "Wi-Fi standby RAT parked to gsm (saved: $saved_rat)"
return 0
fi
rm -f "$RAT_SAVED" 2>/dev/null || true
log "failed to park Wi-Fi standby RAT to gsm"
return 1
}
unpark_wifi_rat() {
[ -f "$RAT_PARKED" ] || return 0
saved_rat=""
[ -r "$RAT_SAVED" ] && { IFS= read -r saved_rat < "$RAT_SAVED" 2>/dev/null || saved_rat=""; }
[ -n "$saved_rat" ] || saved_rat="gsm|umts|lte"
if $QMI --nas-set-system-selection-preference="$saved_rat" >/dev/null 2>&1; then
log "Wi-Fi standby RAT restored ($saved_rat)"
else
log "failed to restore Wi-Fi standby RAT ($saved_rat)"
fi
rm -f "$RAT_PARKED" "$RAT_SAVED" 2>/dev/null || true
}
screenoff() { screenoff() {
apply_cpu_lpm
mute_wifi_ipv6_ra
apply_modem_drx cached || true apply_modem_drx cached || true
if [ "$WIFI_STANDBY_RAT" = "gsm" ]; then
rtok="$(date +%s)-$$"
printf '%s\n' "$rtok" > "$RAT_TOKEN"
(
sleep 30
cur=""
[ -r "$RAT_TOKEN" ] && { read -r cur < "$RAT_TOKEN" 2>/dev/null || cur=""; }
[ "$cur" = "$rtok" ] || exit 0
"$0" _park_rat >/dev/null 2>&1
) &
fi
[ "$DSDS_SECONDARY_MODE" = "eco" ] || return 0 [ "$DSDS_SECONDARY_MODE" = "eco" ] || return 0
token="$(date +%s)-$$" token="$(date +%s)-$$"
printf '%s\n' "$token" > "$TOKEN" printf '%s\n' "$token" > "$TOKEN"
@@ -168,7 +265,11 @@ screenoff() {
} }
screenon() { screenon() {
rm -f "$TOKEN" 2>/dev/null || true rm -f "$TOKEN" "$RAT_TOKEN" 2>/dev/null || true
set_spm_bool "$SPM_PARAM_DIR/screen_off" 0
apply_cpu_lpm
restore_wifi_ipv6_ra
unpark_wifi_rat
unpark unpark
apply_modem_drx cached || true apply_modem_drx cached || true
} }
@@ -176,6 +277,9 @@ screenon() {
apply_now() { apply_now() {
rm -f "$BOOTTOKEN" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true rm -f "$BOOTTOKEN" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true
write_modprobe || true write_modprobe || true
apply_cpu_lpm
[ "$WIFI_SCREEN_OFF_IPV6_MUTE" = "1" ] || restore_wifi_ipv6_ra
[ "$WIFI_STANDBY_RAT" = "gsm" ] || unpark_wifi_rat
apply_modem_drx force || true apply_modem_drx force || true
} }
@@ -198,8 +302,9 @@ modem_ready() {
} }
boot() { boot() {
rm -f "$TOKEN" "$PARKED" "$AIDFILE" "$SLOTFILE" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true rm -f "$TOKEN" "$RAT_TOKEN" "$PARKED" "$AIDFILE" "$SLOTFILE" "$RAT_PARKED" "$RAT_SAVED" "$IPV6_RA_SAVED" "$READYSTAMP" "$RUNDIR"/drx.wwan* 2>/dev/null || true
write_modprobe || true write_modprobe || true
apply_cpu_lpm
btok="$$-$(cat /proc/uptime 2>/dev/null | awk '{print $1}' || echo 0)" btok="$$-$(cat /proc/uptime 2>/dev/null | awk '{print $1}' || echo 0)"
printf '%s\n' "$btok" > "$BOOTTOKEN" printf '%s\n' "$btok" > "$BOOTTOKEN"
( (
@@ -223,16 +328,37 @@ boot() {
) >/dev/null 2>&1 & ) >/dev/null 2>&1 &
} }
debugfs_summary() {
dir="$1"
[ -d "$dir" ] || { printf 'n/a'; return 0; }
out=""
for f in "$dir"/*; do
[ -r "$f" ] || continue
val="$(tr '\n\t' ' ' < "$f" 2>/dev/null | awk '{$1=$1; print}')"
[ -n "$val" ] && out="${out:+$out; }${f##*/}: $val"
done
printf '%s' "${out:-n/a}"
}
status() { status() {
printf 'WIFI_LISTEN_INTERVAL=%s\n' "$WIFI_LISTEN_INTERVAL" printf 'WIFI_LISTEN_INTERVAL=%s\n' "$WIFI_LISTEN_INTERVAL"
printf 'MODEM_DRX_MODE=%s\n' "$MODEM_DRX_MODE" printf 'MODEM_DRX_MODE=%s\n' "$MODEM_DRX_MODE"
printf 'DSDS_SECONDARY_MODE=%s\n' "$DSDS_SECONDARY_MODE" printf 'DSDS_SECONDARY_MODE=%s\n' "$DSDS_SECONDARY_MODE"
printf 'DSDS_PARK_DELAY=%s\n' "$DSDS_PARK_DELAY" printf 'DSDS_PARK_DELAY=%s\n' "$DSDS_PARK_DELAY"
printf 'CPU_RPM_SLEEP=%s\n' "$CPU_RPM_SLEEP"
printf 'CPU_L2_SLEEP=%s\n' "$CPU_L2_SLEEP"
printf 'WIFI_SCREEN_OFF_IPV6_MUTE=%s\n' "$WIFI_SCREEN_OFF_IPV6_MUTE"
printf 'WIFI_STANDBY_RAT=%s\n' "$WIFI_STANDBY_RAT"
if [ -f "$PARKED" ]; then if [ -f "$PARKED" ]; then
printf 'secondary_parked=yes\n' printf 'secondary_parked=yes\n'
else else
printf 'secondary_parked=no\n' printf 'secondary_parked=no\n'
fi fi
if [ -f "$RAT_PARKED" ]; then
printf 'rat_parked=yes\n'
else
printf 'rat_parked=no\n'
fi
if [ -r "$MODPROBE" ]; then if [ -r "$MODPROBE" ]; then
printf 'modprobe_conf=%s (%s)\n' "$MODPROBE" "$(tail -n 1 "$MODPROBE")" printf 'modprobe_conf=%s (%s)\n' "$MODPROBE" "$(tail -n 1 "$MODPROBE")"
else else
@@ -240,6 +366,14 @@ status() {
fi fi
printf 'wcn36xx_param=%s\n' "$(cat /sys/module/wcn36xx/parameters/listen_interval 2>/dev/null || echo n/a)" printf 'wcn36xx_param=%s\n' "$(cat /sys/module/wcn36xx/parameters/listen_interval 2>/dev/null || echo n/a)"
printf 'wcn36xx_screen_off_offload=%s\n' "$(cat /sys/module/wcn36xx/parameters/screen_off_offload 2>/dev/null || echo n/a)" printf 'wcn36xx_screen_off_offload=%s\n' "$(cat /sys/module/wcn36xx/parameters/screen_off_offload 2>/dev/null || echo n/a)"
printf 'cpuidle_rpm_sleep=%s\n' "$(cat "$SPM_PARAM_DIR/rpm_sleep" 2>/dev/null || echo n/a)"
printf 'cpuidle_l2_sleep=%s\n' "$(cat "$SPM_PARAM_DIR/l2_sleep" 2>/dev/null || echo n/a)"
printf 'cpuidle_screen_off=%s\n' "$(cat "$SPM_PARAM_DIR/screen_off" 2>/dev/null || echo n/a)"
printf 'cpuidle_rpm_sleep_count=%s\n' "$(cat "$SPM_PARAM_DIR/rpm_sleep_count" 2>/dev/null || echo n/a)"
printf 'cpuidle_l2_off_count=%s\n' "$(cat "$SPM_PARAM_DIR/l2_off_count" 2>/dev/null || echo n/a)"
printf 'wlan0_accept_ra=%s\n' "$(cat "$ACCEPT_RA" 2>/dev/null || echo n/a)"
printf 'qcom_stats=%s\n' "$(debugfs_summary /sys/kernel/debug/qcom_stats)"
printf 'qcom_rpm_master_stats=%s\n' "$(debugfs_summary /sys/kernel/debug/qcom_rpm_master_stats)"
drx_summary="$(timeout 8 /usr/libexec/msm-modem-uim-selection at all 'AT$QCDRX?' 2>/dev/null | awk ' drx_summary="$(timeout 8 /usr/libexec/msm-modem-uim-selection at all 'AT$QCDRX?' 2>/dev/null | awk '
/^\[wwan0at/ { gsub(/[\[\]]/, "", $0); p=$0; next } /^\[wwan0at/ { gsub(/[\[\]]/, "", $0); p=$0; next }
/\$QCDRX:/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $0); if (p != "") out = (out ? out " " : "") p ":" $0 } /\$QCDRX:/ { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $0); if (p != "") out = (out ? out " " : "") p ":" $0 }
@@ -255,7 +389,8 @@ case "${1:-}" in
screenoff) screenoff ;; screenoff) screenoff ;;
screenon) screenon ;; screenon) screenon ;;
_park) park ;; _park) park ;;
unpark) unpark ;; _park_rat) park_wifi_rat ;;
unpark) restore_wifi_ipv6_ra; unpark_wifi_rat; unpark ;;
status) status ;; status) status ;;
*) *)
printf 'Usage: %s [boot|apply|modem-ready|screenoff|screenon|unpark|status]\n' "${0##*/}" >&2 printf 'Usage: %s [boot|apply|modem-ready|screenoff|screenon|unpark|status]\n' "${0##*/}" >&2
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -201,50 +201,4 @@ fi
fi fi
) & ) &
first_iter=1 exec /usr/bin/bananarchy-session-loop "$SESSION_PID_FILE"
while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
if pidof -s dwm >/dev/null 2>&1; then
exit 0
fi
# U14: skip X resource/wallpaper work when the panel is powered down.
_dark=0
if [ -r /sys/class/backlight/backlight/brightness ]; then
_bl=1
read -r _bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _bl=1
[ "${_bl:-1}" = "0" ] && _dark=1
fi
if [ "$_dark" = "0" ]; then
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
/usr/bin/bananarchy-sync-dunst-theme --no-restart >/dev/null 2>&1 || true
fi
WP_FILE="/usr/share/wallpapers/bananarchy.png"
if [ -f "$XDG_CONFIG_HOME/sxmo/wallpaper" ]; then
custom_wp="$(head -n 1 "$XDG_CONFIG_HOME/sxmo/wallpaper" 2>/dev/null)"
[ -n "$custom_wp" ] && [ -f "$custom_wp" ] && WP_FILE="$custom_wp"
fi
WP_FLAG="--bg-fill"
if [ -f "$XDG_CONFIG_HOME/sxmo/wallpaper_mode" ]; then
wp_mode="$(head -n 1 "$XDG_CONFIG_HOME/sxmo/wallpaper_mode" 2>/dev/null)"
case "$wp_mode" in
scale|--bg-scale) WP_FLAG="--bg-scale" ;;
max|--bg-max) WP_FLAG="--bg-max" ;;
center|--bg-center) WP_FLAG="--bg-center" ;;
tile|--bg-tile) WP_FLAG="--bg-tile" ;;
*) WP_FLAG="--bg-fill" ;;
esac
fi
if [ "$_dark" = "0" ]; then ( feh --no-fehbg "$WP_FLAG" "$WP_FILE" >/dev/null 2>&1 </dev/null & ); fi
if [ "$first_iter" = "0" ]; then
pidof -s fcitx5 >/dev/null 2>&1 || superctl start fcitx5 >/dev/null 2>&1 || ( /usr/bin/bananarchy-fcitx5.sh </dev/null & )
fi
first_iter=0
if [ -f /tmp/bananarchy_ext_logging ]; then
dwm >/tmp/dwm.log 2>&1 || true
else
dwm >/dev/null 2>&1 || true
fi
if [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" != "$$" ] || pidof -s dwm >/dev/null 2>&1; then
exit 0
fi
sleep 0.2
done
+1 -181
View File
@@ -1,182 +1,2 @@
#!/bin/sh #!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only exec /usr/bin/bananarchy-modemmonitor "$@"
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
# see networkmanager documentation for these state names
statenumtoname() {
case "$1" in
"int32 -1") printf "failed" ;;
"int32 0") printf "unknown" ;;
"int32 1") printf "initializing" ;;
"int32 2") printf "locked" ;;
"int32 3") printf "disabled" ;;
"int32 4") printf "disabling" ;;
"int32 5") printf "enabling" ;;
"int32 6") printf "enabled" ;;
"int32 7") printf "searching" ;;
"int32 8") printf "registered" ;;
"int32 9") printf "disconnecting" ;;
"int32 10") printf "connecting" ;;
"int32 11") printf "connected" ;;
*) printf "ERROR" ;;
esac
}
mainloop() {
# get initial modem state and handle SIM2/QMI PIN lock or unprovisioned slot
(
tries=0
newstate=""
while [ "$tries" -lt 15 ]; do
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
if [ -n "$newstate" ]; then
break
fi
sleep 2
tries=$((tries + 1))
done
uim_st="$(doas -n /usr/libexec/msm-modem-uim-selection status 2>/dev/null || /usr/libexec/msm-modem-uim-selection status 2>/dev/null || true)"
if printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_PIN1_STATE=(enabled-not-verified|blocked)|SLOT[12]_APP_STATE=(pin1|puk1)"; then
newstate="locked"
elif [ "$newstate" = "locked" ] && printf "%s\n" "$uim_st" | grep -q "^MODEM_AVAILABLE=1$"; then
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
if [ "$newstate" = "locked" ]; then
newstate="disabled"
fi
elif printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_STATE=present" && printf "%s\n" "$uim_st" | grep -q "^PRIMARY_GW_SLOT=0$"; then
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
elif printf "%s\n" "$uim_st" | grep -q "^SLOT1_STATE=present$" && printf "%s\n" "$uim_st" | grep -q "^SLOT2_STATE=present$" && printf "%s\n" "$uim_st" | grep -q "^SECONDARY_GW_SLOT=0$"; then
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
fi
if [ -n "$newstate" ]; then
# fake oldstate (boot) and reason (0)
sxmo_hook_modem.sh "boot" "$newstate" "0"
sxmo_hook_statusbar.sh modem
fi
) &
# Monitor Secondary GW SIM calls and SMS in Dual-SIM Dual Standby (DSDS)
(
sleep 4
if [ ! -f /tmp/sxmo_dsds_active ]; then
doas -n /usr/libexec/msm-modem-uim-selection status >/dev/null 2>&1 || /usr/libexec/msm-modem-uim-selection status >/dev/null 2>&1 || true
fi
while : ; do
if [ "$(cat /tmp/sxmo_dsds_active 2>/dev/null || echo 0)" = "1" ]; then
if command -v doas >/dev/null 2>&1; then
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
else
/usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
fi
sleep 30
else
sleep 600
fi
done
) &
# Monitor ModemManager signals using a single dbus-monitor connection
dbus-monitor --system \
"interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" \
"interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" \
"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Sms'" \
"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'" \
"interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'" \
"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd'" |
while read -r line; do
case "$line" in
signal*"interface=org.freedesktop.ModemManager1.Modem.Voice"*"member=CallAdded"*)
( sxmo_modem.sh checkforincomingcalls & )
;;
signal*"interface=org.freedesktop.ModemManager1.Modem.Messaging"*"member=Added"*)
( sxmo_modem.sh checkfornewtexts & )
;;
signal*"path=/org/freedesktop/ModemManager1/SMS/"*"member=PropertiesChanged"*)
( sxmo_modem.sh checkfornewtexts & )
;;
signal*"path=/org/freedesktop/ModemManager1/Call/"*"member=PropertiesChanged"*)
( sxmo_modem.sh checkforfinishedcalls & )
;;
signal*"interface=org.freedesktop.ModemManager1.Modem;"*"member=StateChanged"*)
read -r oldstate || true
read -r newstate || true
read -r reason || true
(
(
sxmo_hook_modem.sh "$(statenumtoname "$oldstate")" \
"$(statenumtoname "$newstate")" \
"$(echo "$reason" | sed 's/uint32 //')"
sxmo_hook_statusbar.sh modem
) &
)
;;
signal*"path=/org/freedesktop/ModemManager1/Modem/"*"member=PropertiesChanged"*)
MODEM="$(echo "$line" | awk -F'[;=]' '{print $6}')"
;;
*"string \"NetworkNotification\""*)
[ -n "${MODEM:-}" ] && ( sxmo_ussd.sh "$MODEM" "NetworkNotification" "" & )
;;
*"string \"NetworkRequest\""*)
[ -n "${MODEM:-}" ] && ( sxmo_ussd.sh "$MODEM" "NetworkRequest" "" & )
;;
esac
done &
if [ -f "${SXMO_MMS_BASE_DIR:-"$HOME"/.mms/modemmanager}/mms" ]; then
# monitor for received mms
dbus-monitor "interface='org.ofono.mms.Service',type='signal',member='MessageAdded'" |
while read -r line; do
if echo "$line" | grep -q '^object path'; then
MESSAGE_PATH="$(echo "$line" | cut -d\" -f2)"
fi
if echo "$line" | grep -q 'string "received"'; then
sxmo_mms.sh processmms "$MESSAGE_PATH"
fi
done &
fi
if [ -f "${SXMO_VVM_BASE_DIR:-"$HOME"/.vvm/modemmanager}/vvm" ]; then
# monitor for vvm (Visual Voice Mail)
VVM_START=0
dbus-monitor "interface='org.kop316.vvm.Service',type='signal',member='MessageAdded'" |
while read -r line; do
if echo "$line" | grep -q '^object path'; then
VVM_ID="$(echo "$line" | cut -d\" -f2 | rev | cut -d'/' -f1 | rev)"
VVM_START=1
fi
if echo "$line" | grep -q '^]'; then
VVM_START=0
sxmo_vvm.sh processvvm "$VVM_DATE" "$VVM_SENDER" "$VVM_ID" "$VVM_ATTACHMENT"
fi
if [ "$VVM_START" -eq 1 ]; then
if echo "$line" | grep -q '^string "Date"'; then
read -r line
VVM_DATE="$(echo "$line" | cut -d\" -f2)"
elif echo "$line" | grep -q '^string "Sender"'; then
read -r line
VVM_SENDER="$(echo "$line" | cut -d\" -f2)"
elif echo "$line" | grep -q '^string "Attachments"'; then
read -r line
VVM_ATTACHMENT="$(echo "$line" | cut -d\" -f2)"
fi
fi
done &
fi
wait
}
# new session, clean up all phone related files
rm "$XDG_RUNTIME_DIR/sxmo_calls/"* 2>/dev/null || true
rm -f "$XDG_RUNTIME_DIR"/sxmo.ring.pid 2>/dev/null
rm -f "$SXMO_NOTIFDIR"/incomingcall* 2>/dev/null
mainloop
+4 -30
View File
@@ -23,7 +23,7 @@ clear_all() {
rm -f "$SXMO_NOTIFDIR"/* 2>/dev/null || true rm -f "$SXMO_NOTIFDIR"/* 2>/dev/null || true
dunstctl close-all >/dev/null 2>&1 || true dunstctl close-all >/dev/null 2>&1 || true
dunstctl history-clear >/dev/null 2>&1 || true dunstctl history-clear >/dev/null 2>&1 || true
pkill -x dunstify >/dev/null 2>&1 || true killall -q dunstify >/dev/null 2>&1 || true
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
} }
@@ -73,34 +73,7 @@ _notifications_hook() {
} }
monitor() { monitor() {
mkdir -p "$SXMO_NOTIFDIR" exec /usr/bin/bananarchy-notifmonitor
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
_handle_new_notif_file "$file" "boot"
done
_notifications_hook
fifo="$(mktemp -u)"
mkfifo "$fifo"
inotifywait -mq -e close_write,moved_to,delete "$SXMO_NOTIFDIR" >> "$fifo" &
inotif_pid=$!
finish() {
kill "$inotif_pid" 2>/dev/null || true
rm -f "$fifo"
exit
}
trap 'finish' TERM INT EXIT
while read -r notif_folder notif_type notif_file; do
if echo "$notif_type" | grep -qE "CLOSE_WRITE|MOVED_TO"; then
_handle_new_notif_file "$notif_folder$notif_file"
fi
_notifications_hook
done < "$fifo"
wait "$inotif_pid"
} }
_menu_lines() { _menu_lines() {
@@ -200,7 +173,8 @@ new() {
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$tmp_notif" printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$tmp_notif"
mv -f "$tmp_notif" "$SXMO_NOTIFDIR/$id" mv -f "$tmp_notif" "$SXMO_NOTIFDIR/$id"
if ! pgrep -f "sxmo_notifs.sh monitor" >/dev/null 2>&1; then if ! pidof -s bananarchy-notifmonitor >/dev/null 2>&1 && \
! pgrep -f "sxmo_notifs.sh monitor" >/dev/null 2>&1; then
sxmo_hook_notification.sh "$SXMO_NOTIFDIR/$id" & sxmo_hook_notification.sh "$SXMO_NOTIFDIR/$id" &
fi fi
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
exec /usr/bin/bananarchy-run-aligned "$@"
+1 -184
View File
@@ -1,185 +1,2 @@
#!/bin/sh #!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only exec /usr/bin/bananarchy-soundmonitor "$@"
# Copyright 2023 Sxmo Contributors
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
find_jack_event_dev() {
for sysname in /sys/class/input/event*/device/name; do
[ -r "$sysname" ] || continue
read -r dname < "$sysname" 2>/dev/null || continue
case "$dname" in
*[Jj]ack*|*[Hh]eadset*)
ev="${sysname%/device/name}"
ev="/dev/input/${ev##*/}"
if [ -c "$ev" ]; then
printf "%s\n" "$ev"
return 0
fi
;;
esac
done
return 1
}
is_hp_plugged() {
jdev="$1"
if [ -n "$jdev" ] && command -v evtest >/dev/null 2>&1; then
evtest --query "$jdev" EV_SW SW_HEADPHONE_INSERT >/dev/null 2>&1
rc=$?
[ "$rc" -eq 10 ] && return 0
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cget "name='Headphone Jack'" 2>/dev/null | grep -q ": values=on" && return 0
fi
return 1
}
is_mic_plugged() {
jdev="$1"
if [ -n "$jdev" ] && command -v evtest >/dev/null 2>&1; then
evtest --query "$jdev" EV_SW SW_MICROPHONE_INSERT >/dev/null 2>&1
rc=$?
[ "$rc" -eq 10 ] && return 0
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cget "name='Mic Jack'" 2>/dev/null | grep -q ": values=on" && return 0
fi
return 1
}
handle_jack_insert() {
jdev="$1"
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
if [ "$cur_out" != "Headphones" ]; then
printf "%s\n" "$cur_out" > /tmp/sxmo_prev_out_device 2>/dev/null || true
fi
printf "1\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
if is_mic_plugged "$jdev"; then
printf "Headset\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
else
printf "Mic1\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
fi
sxmo_audio.sh device set Headphones >/dev/null 2>&1 || true
sxmo_log "Wired headphones plugged in -> routed audio to Headphones"
}
handle_jack_remove() {
printf "0\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
printf "Mic1\n" > /tmp/sxmo_audio_in_device 2>/dev/null || true
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
target_out="Speaker"
if [ -r /tmp/sxmo_in_call ]; then
read -r incall < /tmp/sxmo_in_call 2>/dev/null || incall=0
if [ "$incall" = "1" ]; then
target_out="Earpiece"
fi
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
sxmo_log "Wired headphones unplugged -> routed audio to $target_out"
}
monitor_jack_events() {
while : ; do
jdev="$(find_jack_event_dev || true)"
if [ -z "$jdev" ] || ! command -v evtest >/dev/null 2>&1; then
sleep 5
continue
fi
if is_hp_plugged "$jdev"; then
handle_jack_insert "$jdev"
else
printf "0\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
if [ -n "$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')" ]; then
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
else
sxmo_audio.sh device apply >/dev/null 2>&1 || true
fi
fi
evtest "$jdev" 2>/dev/null | while read -r line; do
case "$line" in
*SW_HEADPHONE_INSERT*value\ 1*)
sleep 0.1
handle_jack_insert "$jdev"
;;
*SW_HEADPHONE_INSERT*value\ 0*)
handle_jack_remove
;;
*SW_MICROPHONE_INSERT*value\ 1*)
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
;;
*SW_MICROPHONE_INSERT*value\ 0*)
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
;;
esac
done
sleep 2
done
}
handle_change() {
prev_bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -n "$prev_bt_sink" ]; then
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
if [ "$cur_out" != "Bluetooth" ]; then
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
else
sxmo_audio.sh device apply >/dev/null 2>&1 || true
fi
fi
pactl subscribe 2>/dev/null | while read -r line; do
case "$line" in
*"Event 'new' on sink"*|*"Event 'new' on card"*|*"Event 'change' on card"*)
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -n "$bt_sink" ] && [ "$bt_sink" != "$prev_bt_sink" ]; then
prev_bt_sink="$bt_sink"
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
sxmo_log "Bluetooth sink $bt_sink detected -> routed audio to Bluetooth"
fi
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
;;
*"Event 'remove' on sink"*|*"Event 'remove' on card"*)
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
if [ -z "$bt_sink" ] && [ -n "$prev_bt_sink" ]; then
prev_bt_sink=""
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
if [ "$cur_out" = "Bluetooth" ]; then
if [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" = "1" ]; then
sxmo_audio.sh device set Headphones >/dev/null 2>&1 || true
elif [ -r /tmp/sxmo_in_call ]; then
sxmo_audio.sh device set Earpiece >/dev/null 2>&1 || true
else
sxmo_audio.sh device set Speaker >/dev/null 2>&1 || true
fi
sxmo_log "Bluetooth sink removed -> restored local audio route"
fi
fi
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
;;
*"Event 'change' on sink"*|*"Event 'change' on source"*)
if [ ! -d /tmp/sxmo_volset.lock ]; then
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
fi
;;
esac
done
}
cleanup() {
kill 0 2>/dev/null || true
}
trap cleanup EXIT INT TERM
monitor_jack_events &
while : ; do
handle_change || true
# U10: pactl subscribe is event-driven; only back off after a failure.
sleep 10
done
+5 -2
View File
@@ -70,12 +70,12 @@ xorgdisplay() {
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'powersave\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true printf 'powersave\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi fi
xset s off s noblank >/dev/null 2>&1 || true
xset dpms force off >/dev/null 2>&1 || true
# K5: pin the Adreno 304 devfreq to its minimum OPP while dark. # K5: pin the Adreno 304 devfreq to its minimum OPP while dark.
if [ -w /sys/class/devfreq/1c00000.gpu/governor ]; then if [ -w /sys/class/devfreq/1c00000.gpu/governor ]; then
printf 'powersave\n' > /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true printf 'powersave\n' > /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true
fi fi
xset s off s noblank >/dev/null 2>&1 || true
xset dpms force off >/dev/null 2>&1 || true
# Power policy: park the secondary SIM after the configured dark delay. # Power policy: park the secondary SIM after the configured dark delay.
/usr/bin/bananarchy-power-policy.sh screenoff >/dev/null 2>&1 & /usr/bin/bananarchy-power-policy.sh screenoff >/dev/null 2>&1 &
;; ;;
@@ -85,6 +85,9 @@ xorgdisplay() {
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}" wake; then
return 0 return 0
fi fi
if [ -w /sys/module/cpuidle_qcom_spm/parameters/screen_off ]; then
printf 'N\n' > /sys/module/cpuidle_qcom_spm/parameters/screen_off 2>/dev/null || true
fi
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'schedutil\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true printf 'schedutil\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi fi
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -1 +0,0 @@
console=ttyMSM0,115200
@@ -979,7 +979,7 @@ PY
fi fi
SIM_WAIT_TIME=2 SIM_WAIT_TIME=2
provision_slot "$target" 4 provision_slot "$target" 4
pkill -f "dsds-daemon" 2>/dev/null || true killall -q bananarchy-dsds 2>/dev/null || true
if [ "${3:-}" = "--swap-gw" ]; then if [ "${3:-}" = "--swap-gw" ]; then
spawn_enable_and_register "$target" 2 spawn_enable_and_register "$target" 2
else else
@@ -2409,902 +2409,7 @@ PY
;; ;;
dsds-daemon) dsds-daemon)
exec python3 - dsds-daemon << 'PY' exec /usr/bin/bananarchy-dsds
import datetime, fcntl, os, select, socket, struct, subprocess, sys, time
lock_fd = open("/tmp/dsds_daemon.lock", "w")
try:
fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except Exception:
sys.exit(0)
try:
os.chmod("/tmp/dsds_daemon.lock", 0o666)
except Exception:
pass
try:
while os.waitpid(-1, os.WNOHANG)[0] > 0:
pass
except Exception:
pass
AF_QIPCRTR = 42
QRTR_PORT_CTRL = 0xfffffffe
QRTR_TYPE_NEW_SERVER = 4
QRTR_TYPE_NEW_LOOKUP = 10
QMI_SERVICE_UIM = 11
QMI_SERVICE_WMS = 5
QMI_SERVICE_VOICE = 9
CALLS_DIR = "/run/user/10000/sxmo_calls"
LOG_DIR = "/home/user/.local/share/sxmo/modem"
MODEMLOG = os.path.join(LOG_DIR, "modemlog.tsv")
# This daemon runs as root (via doas), but everything it creates under the
# user's runtime and data directories must stay owned by "user": the sxmo
# scripts that run as the user append to modemlog.tsv and create call state
# files under `set -e`, so a root-owned directory or log file makes them
# abort (no call log entries, and rejected calls never get hung up).
try:
import pwd
_pw = pwd.getpwnam("user")
USER_UID, USER_GID = _pw.pw_uid, _pw.pw_gid
except Exception:
USER_UID, USER_GID = 10000, 10000
def chown_user(path):
try:
os.chown(path, USER_UID, USER_GID)
except Exception:
pass
def ensure_user_dir(path, stop_at):
# Create `path` (and missing parents below `stop_at`) owned by the user,
# and repair ownership of directories a previous root-run instance created.
parts = []
cur = path
while cur and cur != stop_at and cur != "/":
parts.append(cur)
cur = os.path.dirname(cur)
for d in reversed(parts):
try:
os.mkdir(d, 0o755)
except FileExistsError:
pass
except Exception:
return
try:
if os.stat(d).st_uid == 0:
chown_user(d)
except Exception:
pass
def append_modemlog(line):
ensure_user_dir(LOG_DIR, "/home/user")
try:
with open(MODEMLOG, "a", encoding="utf-8") as f:
f.write(line)
f.flush()
os.fsync(f.fileno())
except Exception:
return
chown_user(MODEMLOG)
# Only create the call state directory inside an existing user runtime dir;
# never create /run/user/10000 itself as root.
if os.path.isdir("/run/user/10000"):
ensure_user_dir(CALLS_DIR, "/run/user/10000")
ensure_user_dir(LOG_DIR, "/home/user")
# Repair logs and directories left root-owned by earlier daemon versions.
try:
for root_dir, dirs, files in os.walk(LOG_DIR):
for name in dirs + files:
p = os.path.join(root_dir, name)
if os.lstat(p).st_uid == 0:
chown_user(p)
except Exception:
pass
def lookup_srv(sid):
try:
ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
node, _ = ls.getsockname()
ls.sendto(struct.pack("<IIIII", QRTR_TYPE_NEW_LOOKUP, sid, 0, 0, 0), (node, QRTR_PORT_CTRL))
addr = None
while True:
r, _, _ = select.select([ls], [], [], 0.2)
if not r:
break
data, _ = ls.recvfrom(256)
if len(data) >= 20:
cmd, srv, inst, srv_node, srv_port = struct.unpack("<IIIII", data[:20])
if cmd == QRTR_TYPE_NEW_SERVER:
if srv == sid and srv_port != 0:
addr = (srv_node, srv_port)
if srv == 0 and srv_node == 0 and srv_port == 0:
break
ls.close()
return addr
except Exception:
return None
def parse_tlvs(resp):
res = {}
pos = 7
while pos + 3 <= len(resp):
tt, tl = struct.unpack("<BH", resp[pos:pos+3])
pos += 3
res[tt] = resp[pos:pos+tl]
pos += tl
return res
pending_inds = []
def qmi_req(s, addr, txn, msg_id, tlvs=b"", timeout=1.0):
s.sendto(struct.pack("<BHHH", 0x00, txn, msg_id, len(tlvs)) + tlvs, addr)
deadline = time.time() + timeout
while time.time() < deadline:
r, _, _ = select.select([s], [], [], max(0.05, deadline - time.time()))
if not r:
return {}
resp, _ = s.recvfrom(4096)
if len(resp) >= 7 and resp[0] == 0x04:
pending_inds.append((s, resp))
continue
if len(resp) >= 7 and resp[0] == 0x02:
r_txn, r_msg, _ = struct.unpack("<HHH", resp[1:7])
if r_txn == txn and r_msg == msg_id:
return parse_tlvs(resp)
return {}
def run_user_cmd(cmd_str, extra_env=None):
env = os.environ.copy()
env["DISPLAY"] = ":0"
env["XDG_RUNTIME_DIR"] = "/run/user/10000"
env["HOME"] = "/home/user"
env["PATH"] = "/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin"
if extra_env:
env.update(extra_env)
try:
p = subprocess.Popen(
["su", "-m", "user", "-c", f"export DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 HOME=/home/user PATH=/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin; ({cmd_str}) >/dev/null 2>&1 &"],
env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
p.wait(timeout=2.0)
except Exception:
pass
def send_fifo(fifo_path, line):
try:
if os.path.exists(fifo_path):
fd = os.open(fifo_path, os.O_WRONLY | os.O_NONBLOCK)
os.write(fd, (line + "\n").encode("utf-8"))
os.close(fd)
except Exception:
pass
GSM7_BASIC = (
"@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5"
"\u0394_\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\x1b\u00c6\u00e6\u00df\u00c9"
" !\"#\u00a4%&'()*+,-./0123456789:;<=>?"
"\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6\u00d1\u00dc\u00a7"
"\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1\u00fc\u00e0"
)
GSM7_EXT = {
0x0A: "\f", 0x14: "^", 0x28: "{", 0x29: "}", 0x2F: "\\",
0x3C: "[", 0x3D: "~", 0x3E: "]", 0x40: "|", 0x65: "\u20ac"
}
def decode_bcd_addr(data, num_digits, ton_npi):
ton = (ton_npi >> 4) & 0x07
if ton == 5:
# Alphanumeric 7-bit GSM address
total_septets = (num_digits * 4) // 7
septets = []
esc = False
for i in range(total_septets):
bit_off = i * 7
byte_idx = bit_off // 8
shift = bit_off % 8
if byte_idx >= len(data):
break
val = (data[byte_idx] >> shift) & 0x7F
if shift > 1 and (byte_idx + 1) < len(data):
val |= (data[byte_idx + 1] << (8 - shift)) & 0x7F
if esc:
septets.append(GSM7_EXT.get(val, ""))
esc = False
elif val == 0x1B:
esc = True
else:
septets.append(GSM7_BASIC[val] if val < len(GSM7_BASIC) else "")
return "".join(septets).strip("@ ")
prefix = "+" if ton == 1 else ""
digits = []
for b in data:
lo = b & 0x0F
hi = (b >> 4) & 0x0F
if lo < 10:
digits.append(str(lo))
if hi < 10 and len(digits) < num_digits:
digits.append(str(hi))
return prefix + "".join(digits[:num_digits])
def _parse_deliver_tpdu(pdu, pos):
try:
if pos < 0 or pos + 12 > len(pdu):
return None
first_octet = pdu[pos]
mti = first_octet & 0x03
if mti != 0:
return None
udhi = (first_octet & 0x40) != 0
pos += 1
oa_digits = pdu[pos]
oa_ton_npi = pdu[pos + 1]
if oa_digits > 24 or (oa_ton_npi & 0x80) == 0:
return None
oa_byte_len = (oa_digits + 1) // 2
if pos + 2 + oa_byte_len + 10 > len(pdu):
return None
oa_bytes = pdu[pos + 2 : pos + 2 + oa_byte_len]
sender = decode_bcd_addr(oa_bytes, oa_digits, oa_ton_npi)
pos += 2 + oa_byte_len
pid = pdu[pos]
dcs = pdu[pos + 1]
scts = pdu[pos + 2 : pos + 9]
udl = pdu[pos + 9]
ud = pdu[pos + 10 :]
# Validate and decode SCTS (YY MM DD HH MM SS TZ)
def unbcd(b):
lo = b & 0x0F
hi = (b >> 4) & 0x0F
if lo > 9 or hi > 9:
raise ValueError("invalid BCD")
return (lo * 10) + hi
yr = 2000 + unbcd(scts[0])
mo = unbcd(scts[1])
dy = unbcd(scts[2])
hr = unbcd(scts[3])
mi = unbcd(scts[4])
sc = unbcd(scts[5])
if not (1 <= mo <= 12 and 1 <= dy <= 31 and 0 <= hr <= 23 and 0 <= mi <= 59 and 0 <= sc <= 59):
return None
iso_ts = f"{yr:04d}-{mo:02d}-{dy:02d}T{hr:02d}:{mi:02d}:{sc:02d}"
csms_ref = None
csms_total = 1
csms_seq = 1
udh_bytes = 0
if udhi and len(ud) >= 1:
udh_len = ud[0]
udh_bytes = 1 + udh_len
if udh_bytes > len(ud):
return None
upos = 1
while upos + 2 <= udh_bytes and upos + 2 <= len(ud):
iei = ud[upos]
ielen = ud[upos + 1]
iedata = ud[upos + 2 : upos + 2 + ielen]
upos += 2 + ielen
if iei == 0x00 and len(iedata) >= 3:
csms_ref, csms_total, csms_seq = iedata[0], iedata[1], iedata[2]
elif iei == 0x08 and len(iedata) >= 4:
csms_ref = (iedata[0] << 8) | iedata[1]
csms_total, csms_seq = iedata[2], iedata[3]
if csms_ref is not None and (csms_total < 1 or csms_seq < 1 or csms_seq > csms_total):
csms_ref = None
csms_total = 1
csms_seq = 1
# Determine alphabet from 3GPP TS 23.038 DCS
if (dcs & 0xC0) in (0x00, 0x40):
alphabet = (dcs >> 2) & 0x03
if alphabet == 3:
alphabet = 0
elif (dcs & 0xF0) == 0xE0:
alphabet = 2
elif (dcs & 0xF0) in (0xC0, 0xD0):
alphabet = 0
elif (dcs & 0xF0) == 0xF0:
alphabet = 1 if (dcs & 0x04) else 0
else:
alphabet = 0
if alphabet == 2:
end_byte = min(udl, len(ud))
payload = ud[udh_bytes : end_byte]
if len(payload) % 2 == 1:
payload = payload[:-1]
text = payload.decode("utf-16-be", errors="surrogatepass")
elif alphabet == 1:
end_byte = min(udl, len(ud))
payload = ud[udh_bytes : end_byte]
text = payload.decode("utf-8", errors="replace")
else:
fill_bits = (7 - ((udh_bytes * 8) % 7)) % 7 if udh_bytes > 0 else 0
start_septet = ((udh_bytes * 8) + fill_bits) // 7
chars = []
esc = False
for i in range(start_septet, udl):
bit_off = i * 7
byte_idx = bit_off // 8
shift = bit_off % 8
if byte_idx >= len(ud):
break
val = (ud[byte_idx] >> shift) & 0x7F
if shift > 1 and (byte_idx + 1) < len(ud):
val |= (ud[byte_idx + 1] << (8 - shift)) & 0x7F
if esc:
chars.append(GSM7_EXT.get(val, " "))
esc = False
elif val == 0x1B:
esc = True
else:
chars.append(GSM7_BASIC[val] if val < len(GSM7_BASIC) else "?")
text = "".join(chars)
clean_sender = "".join(
c for c in (sender or "Unknown")
if c not in "/\x00\r\n\t" and ord(c) >= 32
).strip() or "Unknown"
return {
"sender": clean_sender,
"time": iso_ts,
"text": text,
"ref": csms_ref,
"total": csms_total,
"seq": csms_seq,
}
except Exception:
return None
def decode_sms_deliver(pdu, only_tpdu=False):
if not pdu or len(pdu) < 12:
return None
if only_tpdu:
res = _parse_deliver_tpdu(pdu, 0)
if res is not None:
return res
smsc_len = pdu[0]
if 0 <= smsc_len <= 12 and (smsc_len == 0 or (pdu[1] & 0x80) != 0):
return _parse_deliver_tpdu(pdu, 1 + smsc_len)
return None
smsc_len = pdu[0]
if 0 <= smsc_len <= 12 and (smsc_len == 0 or (len(pdu) > 1 and (pdu[1] & 0x80) != 0)):
res = _parse_deliver_tpdu(pdu, 1 + smsc_len)
if res is not None:
return res
return _parse_deliver_tpdu(pdu, 0)
multipart_buf = {}
recent_sms_dedup = {}
def _normalize_sms_text(s):
try:
return s.encode("utf-16", "surrogatepass").decode("utf-16", "replace")
except Exception:
return s
BLOCK_FILE = "/home/user/.config/sxmo/block.tsv"
BLOCK_DIR = "/home/user/.local/share/sxmo/block"
def is_sender_blocked(sender):
try:
if not os.path.isfile(BLOCK_FILE):
return False
norm = "".join(c for c in sender if c.isdigit() or c == "+")
if not norm:
norm = sender.strip()
sfx = norm[-7:] if len(norm) >= 7 else ""
with open(BLOCK_FILE, "r", encoding="utf-8", errors="ignore") as bf:
for line in bf:
raw = line.split("\t", 1)[0].strip()
if not raw:
continue
r_norm = "".join(c for c in raw if c.isdigit() or c in "+*")
if not r_norm:
continue
if r_norm.endswith("*") and len(r_norm) > 1:
if norm.startswith(r_norm[:-1]):
return True
elif r_norm == norm or (sfx and len(r_norm) >= 7 and r_norm[-7:] == sfx):
return True
except Exception:
pass
return False
def deliver_sms_to_sxmo(sender, iso_ts, text, sim_slot):
now_str = datetime.datetime.now().astimezone().isoformat(timespec="seconds")
tsv_text = text.replace("\t", " ").replace("\r", " ").replace("\n", " ")
if is_sender_blocked(sender):
num_dir = os.path.join(BLOCK_DIR, sender)
ensure_user_dir(num_dir, "/home/user")
sms_file = os.path.join(num_dir, "sms.txt")
header = f"Received from {sender} [SIM {sim_slot}] at {now_str}:\n{text}\n\n"
with open(sms_file, "a", encoding="utf-8") as f:
f.write(header)
chown_user(sms_file)
blk_log = os.path.join(BLOCK_DIR, "modemlog.tsv")
try:
with open(blk_log, "a", encoding="utf-8") as f:
f.write(f"{now_str}\trecv_txt\t{sender}\t[SIM {sim_slot}] {tsv_text}\n")
chown_user(blk_log)
except Exception:
pass
send_fifo("/tmp/dwm_plugin_sms.fifo", "REFRESH")
return
num_dir = os.path.join(LOG_DIR, sender)
ensure_user_dir(num_dir, "/home/user")
sms_file = os.path.join(num_dir, "sms.txt")
header = f"Received from {sender} [SIM {sim_slot}] at {now_str}:\n{text}\n\n"
with open(sms_file, "a", encoding="utf-8") as f:
f.write(header)
f.flush()
os.fsync(f.fileno())
append_modemlog(f"{now_str}\trecv_txt\t{sender}\t[SIM {sim_slot}] {tsv_text}\n")
chown_user(sms_file)
send_fifo("/tmp/dwm_plugin_sms.fifo", "REFRESH")
run_user_cmd(
'CONTACTNAME="$(sxmo_contacts.sh --name-or-number "$SXMO_SMS_SENDER" 2>/dev/null || printf "%s" "$SXMO_SMS_SENDER")"; '
'sxmo_notifs.sh new -g "incoming-message-$SXMO_SMS_SENDER" "xsms tailtextlog \'$SXMO_SMS_SENDER\'" "$CONTACTNAME: $SXMO_SMS_TEXT" >/dev/null 2>&1 || true; '
'sxmo_hook_sms.sh "$CONTACTNAME" "$SXMO_SMS_TEXT"',
extra_env={"SXMO_SMS_SENDER": sender, "SXMO_SMS_TEXT": text}
)
def handle_decoded_sms(info, sim_slot):
if not info:
return
now = time.time()
for k, ts in list(recent_sms_dedup.items()):
if now - ts > 120.0:
del recent_sms_dedup[k]
seg_key = ("seg", info["sender"], info["time"], info["ref"], info["total"], info["seq"], info["text"])
if seg_key in recent_sms_dedup and now - recent_sms_dedup[seg_key] < 15.0:
return
recent_sms_dedup[seg_key] = now
if info["ref"] is not None and info["total"] > 1:
done_key = ("csms_done", info["sender"], info["ref"], info["total"])
if done_key in recent_sms_dedup:
return
key = (info["sender"], info["ref"], info["total"])
parts = multipart_buf.setdefault(key, {"ts": now, "time": info["time"], "slot": sim_slot, "segs": {}})
parts["ts"] = now
parts["slot"] = sim_slot
parts["segs"][info["seq"]] = info["text"]
if len(parts["segs"]) >= info["total"]:
full_text = _normalize_sms_text("".join(parts["segs"].get(i, "") for i in range(1, info["total"] + 1)))
msg_time = parts.get("time") or info["time"]
del multipart_buf[key]
recent_sms_dedup[done_key] = now
deliver_sms_to_sxmo(info["sender"], msg_time, full_text, sim_slot)
else:
deliver_sms_to_sxmo(info["sender"], info["time"], _normalize_sms_text(info["text"]), sim_slot)
def flush_stale_multipart(wms_sock=None, wms_addr=None, txn=1, sim_slot=2):
now = time.time()
has_expired = any(now - parts["ts"] >= 45.0 for parts in multipart_buf.values())
if has_expired and wms_sock is not None and wms_addr is not None:
txn = poll_stored_sms(wms_sock, wms_addr, txn, sim_slot)
now = time.time()
for key, parts in list(multipart_buf.items()):
if now - parts["ts"] >= 45.0:
sender, ref, total = key
full_text = _normalize_sms_text("".join(parts["segs"].get(i, "") for i in range(1, total + 1)))
del multipart_buf[key]
recent_sms_dedup[("csms_done", sender, ref, total)] = now
if full_text:
deliver_sms_to_sxmo(sender, parts.get("time", ""), full_text, parts.get("slot", sim_slot))
return txn
def poll_stored_sms(wms_sock, wms_addr, txn, sim_slot):
for _pass in range(3):
found_any = False
decoded_batch = []
for stype in (0, 1):
# WMSListMessages (0x0031): TLV 0x01 = storage_type, TLV 0x11 = message_mode (1 = GW)
tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0031, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHB", 0x11, 1, 1))
txn = (txn % 60000) + 1
raw_list = tlvs.get(0x01, b"")
if len(raw_list) < 4:
continue
cnt = struct.unpack("<I", raw_list[:4])[0]
off = 4
for _ in range(cnt):
if off + 5 > len(raw_list):
break
idx, tag = struct.unpack("<IB", raw_list[off:off+5])
off += 5
# tag 0 = MT read, 1 = MT not read
if tag in (0, 1):
found_any = True
r_tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0022, struct.pack("<BHBI", 0x01, 5, stype, idx) + struct.pack("<BHB", 0x10, 1, 1))
txn = (txn % 60000) + 1
qmi_req(wms_sock, wms_addr, txn, 0x0024, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHI", 0x10, 4, idx) + struct.pack("<BHB", 0x12, 1, 1))
txn = (txn % 60000) + 1
raw_msg = r_tlvs.get(0x01, b"")
if len(raw_msg) >= 4:
dlen = struct.unpack("<H", raw_msg[2:4])[0]
pdu = raw_msg[4:4+dlen]
info = decode_sms_deliver(pdu, only_tpdu=False)
if info:
decoded_batch.append(info)
for info in decoded_batch:
handle_decoded_sms(info, sim_slot)
if not found_any:
break
return txn
def parse_call_info(tlvs):
calls = {}
raw_ci = tlvs[0x01] if 0x01 in tlvs else tlvs.get(0x10, b"")
if len(raw_ci) >= 1:
cnt = raw_ci[0]
off = 1
for _ in range(cnt):
if off + 7 > len(raw_ci):
break
cid, cstate, ctype, cdir, cmode, _, _ = struct.unpack("<BBBBBbB", raw_ci[off:off+7])
off += 7
calls[cid] = {"id": cid, "state": cstate, "dir": cdir, "num": ""}
raw_num = tlvs.get(0x10, b"") if 0x01 in tlvs else tlvs.get(0x11, b"")
if len(raw_num) >= 1:
cnt = raw_num[0]
off = 1
for _ in range(cnt):
if off + 3 > len(raw_num):
break
cid, _, nlen = struct.unpack("<BBB", raw_num[off:off+3])
off += 3
num = raw_num[off:off+nlen].decode("ascii", errors="ignore").strip("\x00 ")
off += nlen
if cid in calls:
calls[cid]["num"] = num
return calls
STATE_MAP = {
1: "dialing",
2: "ringing-in",
3: "active",
4: "dialing",
5: "ringing-out",
6: "held",
7: "waiting",
8: "terminated",
9: "terminated",
10: "setup",
}
active_calls = {}
audio_opened = False
def stop_ringing_user():
run_user_cmd(
"rm -f /tmp/sxmo_call_ringing; "
"sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh 2>/dev/null; "
"pkill -TERM -f 'pw-play.*ring' 2>/dev/null; "
"pkill -TERM -f 'mpv.*ring' 2>/dev/null; "
"pkill -TERM -x sxmo_vibrate 2>/dev/null || true"
)
def set_q6voiced_audio(enable):
global audio_opened
if enable and not audio_opened:
audio_opened = True
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallAdded"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
run_user_cmd("sxmo_modemaudio.sh setup_audio")
elif not enable and audio_opened:
audio_opened = False
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallRemoved"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
run_user_cmd("sxmo_modemaudio.sh reset_audio")
def has_sub1_call_files():
try:
return any(fn.startswith("sub1_") for fn in os.listdir(CALLS_DIR))
except Exception:
return False
def has_mm_call_files():
try:
for fn in os.listdir(CALLS_DIR):
if fn and fn[0].isdigit():
return True
except Exception:
pass
return False
def is_hangup_requested():
try:
return (time.time() - os.path.getmtime("/tmp/sxmo_hangup_requested")) < 3.5
except Exception:
return False
def query_sec_slot(uim_addr, fallback=2):
if not uim_addr:
return fallback
try:
us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
ut = qmi_req(us, uim_addr, 1, 0x002F, timeout=0.08)
us.close()
st_val = ut.get(0x10, b"")
if len(st_val) >= 8:
_, _, sec_gw_idx, _ = struct.unpack("<HHHH", st_val[:8])
if sec_gw_idx != 0xFFFF:
return ((sec_gw_idx >> 8) & 0xFF) + 1
except Exception:
pass
return fallback
def sync_sub1_calls(calls, sim_slot, vs=None, voice_addr=None):
global active_calls
now_str = datetime.datetime.now().astimezone().isoformat(timespec="seconds")
hangup_req = is_hangup_requested()
sent_ended = False
if hangup_req:
for cid, c in list(calls.items()):
if c["state"] not in (8, 9):
if vs is not None and voice_addr is not None:
try:
qmi_req(vs, voice_addr, 55000 + (cid % 100), 0x0021, struct.pack("<BHB", 0x01, 1, cid), timeout=0.2)
except Exception:
pass
c["state"] = 9
for old_cid, old_info in list(active_calls.items()):
if old_cid not in calls:
if old_info.get("state") == "terminated":
del active_calls[old_cid]
else:
calls[old_cid] = {
"id": old_cid,
"state": 9,
"dir": old_info.get("dir", 1),
"num": old_info.get("num", ""),
}
for cid, c in list(calls.items()):
st = STATE_MAP.get(c["state"], "unknown")
if st == "setup":
if c["dir"] == 1 and has_sub1_call_files() and not hangup_req:
st = "dialing"
else:
continue
# Skip calls that are already managed by ModemManager / sxmo_modem.sh on Primary GW
if cid not in active_calls:
if st == "terminated" or hangup_req:
continue
if c["dir"] == 1 and not has_sub1_call_files():
continue
if c["dir"] == 2:
time.sleep(0.35)
if has_mm_call_files():
continue
num = c["num"] or active_calls.get(cid, {}).get("num") or "Unknown"
if num and num != "Unknown" and not num.startswith("+") and len(num) >= 10:
num = "+" + num
c["num"] = num
prev = active_calls.get(cid, {}).get("state")
call_key = f"sub1_{cid}"
# Update /run/user/10000/sxmo_calls/sub1_<id>.<state>
for fn in os.listdir(CALLS_DIR):
if fn == "sub1_dialing.initiatedcall" or (fn.startswith(f"{call_key}.") and not fn.endswith(".initiatedcall") and not fn.endswith(".pickedupcall") and not fn.endswith(".mutedring")):
try:
os.remove(os.path.join(CALLS_DIR, fn))
except Exception:
pass
if st != "terminated" and not hangup_req:
try:
open(os.path.join(CALLS_DIR, f"{call_key}.{st}"), "w").close()
chown_user(os.path.join(CALLS_DIR, f"{call_key}.{st}"))
except Exception:
pass
else:
for fn in os.listdir(CALLS_DIR):
if fn.startswith(f"{call_key}."):
try:
os.remove(os.path.join(CALLS_DIR, fn))
except Exception:
pass
if st == prev:
continue
active_calls[cid] = {"state": st, "num": num, "dir": c["dir"]}
if st == "ringing-in":
if has_mm_call_files():
del active_calls[cid]
continue
append_modemlog(f"{now_str}\tcall_ring\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"INCOMING {call_key} {num} SIM{sim_slot}")
run_user_cmd(f"sxmo_jobs.sh start --group ringing sxmo_hook_ring.sh '{num}'")
elif st in ("dialing", "ringing-out"):
set_q6voiced_audio(True)
if prev not in ("dialing", "ringing-out"):
append_modemlog(f"{now_str}\tcall_dial\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"OUTGOING {call_key} {num} SIM{sim_slot}")
elif st == "active":
stop_ringing_user()
set_q6voiced_audio(True)
append_modemlog(f"{now_str}\tcall_start\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", f"ACTIVE {call_key} {num} SIM{sim_slot}")
elif st == "terminated":
stop_ringing_user()
evt = "call_missed" if prev == "ringing-in" else "call_hangup"
append_modemlog(f"{now_str}\t{evt}\t{num}\t[SIM {sim_slot}]\n")
if not hangup_req:
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
sent_ended = True
has_live = any(v["state"] in ("dialing", "ringing-out", "active", "held", "ringing-in", "waiting") for v in active_calls.values())
if not has_live:
removed_stale = False
for fn in os.listdir(CALLS_DIR):
if fn.startswith("sub1_"):
try:
os.remove(os.path.join(CALLS_DIR, fn))
removed_stale = True
except Exception:
pass
if removed_stale:
stop_ringing_user()
if not sent_ended and not hangup_req:
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
if audio_opened:
set_q6voiced_audio(False)
while True:
wms_addr = lookup_srv(QMI_SERVICE_WMS)
voice_addr = lookup_srv(QMI_SERVICE_VOICE)
uim_addr = lookup_srv(QMI_SERVICE_UIM)
if not (wms_addr and voice_addr):
time.sleep(3)
continue
sec_slot = query_sec_slot(uim_addr, 2)
ws = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
vs = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
w_txn = 1
v_txn = 1
# Bind both sockets to Secondary GW (sub = 1)
qmi_req(ws, wms_addr, w_txn, 0x004C, struct.pack("<BHB", 0x01, 1, 1))
w_txn += 1
qmi_req(ws, wms_addr, w_txn, 0x0001, struct.pack("<BHB", 0x10, 1, 1))
w_txn += 1
# Configure WMS routes on Secondary GW (sub = 1) to match ModemManager:
# Class 0 -> UIM + TRANSFER_AND_ACK (0x03), Class 1/2/3/None -> UIM + STORE_AND_NOTIFY (0x01)
# so the baseband sends 3GPP RP-ACK in hardware for every multipart segment immediately.
route_list = bytes.fromhex("060000000003000100010002000100030001000400010005ff02")
route_tlvs = struct.pack("<BH", 0x01, len(route_list)) + route_list + struct.pack("<BHB", 0x10, 1, 0)
qmi_req(ws, wms_addr, w_txn, 0x0032, route_tlvs)
w_txn += 1
qmi_req(vs, voice_addr, v_txn, 0x0044, struct.pack("<BHB", 0x01, 1, 1))
v_txn += 1
# Register for Voice Call Notification Events (TLV 0x13 = 1)
qmi_req(vs, voice_addr, v_txn, 0x0003, struct.pack("<BHB", 0x13, 1, 1))
v_txn += 1
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
last_poll = time.time()
def screen_is_idle():
if os.path.exists("/tmp/bananarchy_screen_locked") or \
os.path.exists("/run/bananarchy/cover-backlight"):
return True
try:
with open("/sys/class/backlight/backlight/bl_power", "r") as f:
if f.read().strip() != "0":
return True
except Exception:
pass
try:
with open("/sys/class/backlight/backlight/brightness", "r") as f:
if int(f.read().strip()) <= 0:
return True
except Exception:
pass
return False
try:
while True:
if pending_inds:
poll_timeout = 0.0
elif active_calls or has_sub1_call_files():
poll_timeout = 1.0
elif multipart_buf:
poll_timeout = 2.0
elif screen_is_idle():
poll_timeout = None
else:
poll_timeout = 1800.0
r, _, _ = select.select([ws, vs], [], [], poll_timeout)
got_voice_ind = False
events = []
while pending_inds:
events.append(pending_inds.pop(0))
for sock in r:
pkt, _ = sock.recvfrom(4096)
events.append((sock, pkt))
for sock, pkt in events:
if len(pkt) < 7:
continue
flags, txn, mid, _ = struct.unpack("<BHHH", pkt[:7])
if flags != 0x04:
continue
tlvs = parse_tlvs(pkt)
if sock is ws and mid == 0x0001:
sec_slot = query_sec_slot(uim_addr, sec_slot)
# WMSEventReport indication
if 0x11 in tlvs and len(tlvs[0x11]) >= 8:
# Transfer-route MT message: [ack_ind(1), txn_id(4), format(1), len(2), data...]
tr = tlvs[0x11]
ack_ind = tr[0]
mt_txn_id = struct.unpack("<I", tr[1:5])[0]
dlen = struct.unpack("<H", tr[6:8])[0]
pdu = tr[8:8+dlen]
if ack_ind == 0:
# Send QMI_WMS_SEND_ACK (0x0026): TLV 0x01 = [txn_id(4), protocol=1(GW), success=1], TLV 0x10 = 3GPP RP-ACK
ack_tlvs = (
struct.pack("<BHIBB", 0x01, 6, mt_txn_id, 1, 1)
+ struct.pack("<BHBH", 0x10, 5, 0x00, 2)
+ b"\x00\x00"
)
qmi_req(ws, wms_addr, w_txn, 0x0026, ack_tlvs)
w_txn = (w_txn % 60000) + 1
info = decode_sms_deliver(pdu, only_tpdu=True)
if info:
handle_decoded_sms(info, sec_slot)
if 0x10 in tlvs:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
elif sock is vs and mid == 0x002E:
# VoiceAllCallStatusIndication
got_voice_ind = True
sec_slot = query_sec_slot(uim_addr, sec_slot)
calls = parse_call_info(tlvs)
if not any(c["num"] for c in calls.values()):
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
v_txn = (v_txn % 60000) + 1
full_calls = parse_call_info(full_tlvs)
for cid, fc in full_calls.items():
if cid in calls and fc["num"]:
calls[cid]["num"] = fc["num"]
sync_sub1_calls(calls, sec_slot, vs, voice_addr)
if multipart_buf:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
w_txn = flush_stale_multipart(ws, wms_addr, w_txn, sec_slot)
if not got_voice_ind and (active_calls or has_sub1_call_files()):
sec_slot = query_sec_slot(uim_addr, sec_slot)
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
v_txn = (v_txn % 60000) + 1
if full_tlvs:
sync_sub1_calls(parse_call_info(full_tlvs), sec_slot, vs, voice_addr)
if not screen_is_idle() and time.time() - last_poll >= 1800.0:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
last_poll = time.time()
except Exception:
pass
finally:
ws.close()
vs.close()
# U9: back off after a QRTR error instead of re-registering every 2 s.
time.sleep(30)
PY
;; ;;
sim-contacts-import) sim-contacts-import)
@@ -0,0 +1,7 @@
[Unit]
Description=daemon for monitoring modem-related dbuses (calls, sms, mms, etc.)
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/bananarchy-modemmonitor
@@ -0,0 +1,7 @@
[Unit]
Description=display notifications popup messages
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/bananarchy-notifmonitor
@@ -0,0 +1,8 @@
[Unit]
Description=Sxmo: watch audio changes and update the status bar
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/bananarchy-soundmonitor
RestartSec=1s
File diff suppressed because it is too large. Load diff
@@ -5256,7 +5256,7 @@ CONFIG_QCOM_PDR_MSG=m
CONFIG_QCOM_QMI_HELPERS=y CONFIG_QCOM_QMI_HELPERS=y
# CONFIG_QCOM_RAMP_CTRL is not set # CONFIG_QCOM_RAMP_CTRL is not set
CONFIG_QCOM_RMTFS_MEM=y CONFIG_QCOM_RMTFS_MEM=y
# CONFIG_QCOM_RPM_MASTER_STATS is not set CONFIG_QCOM_RPM_MASTER_STATS=y
# CONFIG_QCOM_RPMH is not set # CONFIG_QCOM_RPMH is not set
CONFIG_QCOM_SMEM=y CONFIG_QCOM_SMEM=y
CONFIG_QCOM_SMD_RPM=y CONFIG_QCOM_SMD_RPM=y
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -5256,7 +5256,7 @@ CONFIG_QCOM_PDR_MSG=m
CONFIG_QCOM_QMI_HELPERS=y CONFIG_QCOM_QMI_HELPERS=y
# CONFIG_QCOM_RAMP_CTRL is not set # CONFIG_QCOM_RAMP_CTRL is not set
CONFIG_QCOM_RMTFS_MEM=y CONFIG_QCOM_RMTFS_MEM=y
# CONFIG_QCOM_RPM_MASTER_STATS is not set CONFIG_QCOM_RPM_MASTER_STATS=y
# CONFIG_QCOM_RPMH is not set # CONFIG_QCOM_RPMH is not set
CONFIG_QCOM_SMEM=y CONFIG_QCOM_SMEM=y
CONFIG_QCOM_SMD_RPM=y CONFIG_QCOM_SMD_RPM=y
Binary file not shown.
+16 -7
View File
@@ -101,12 +101,16 @@ if command -v docker >/dev/null 2>&1; then
echo " -> Missing prebuilt kernel modules or DTBs; running scripts/build-kernel-audio.sh..." echo " -> Missing prebuilt kernel modules or DTBs; running scripts/build-kernel-audio.sh..."
"$BASE_DIR/scripts/build-kernel-audio.sh" "$BASE_DIR/scripts/build-kernel-audio.sh"
fi fi
if [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-lid" ] || \ for _req_daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
[ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" ] || \ bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
[ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-volume-keys" ]; then bananarchy-notifmonitor bananarchy-run-aligned \
echo " -> Missing compiled idle daemons; running scripts/build-bananarchy-daemons.sh..." bananarchy-session-loop; do
"$BASE_DIR/scripts/build-bananarchy-daemons.sh" if [ ! -x "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$_req_daemon" ]; then
fi echo " -> Missing compiled daemons; running scripts/build-bananarchy-daemons.sh..."
"$BASE_DIR/scripts/build-bananarchy-daemons.sh"
break
fi
done
if [ ! -f "$BASE_DIR/prebuilt/bantam/bantam" ]; then if [ ! -f "$BASE_DIR/prebuilt/bantam/bantam" ]; then
echo " -> Missing prebuilt bantam binary; running scripts/build-bantam.sh..." echo " -> Missing prebuilt bantam binary; running scripts/build-bantam.sh..."
"$BASE_DIR/scripts/build-bantam.sh" "$BASE_DIR/scripts/build-bantam.sh"
@@ -119,7 +123,10 @@ cp -af "$BASE_DIR/overlay/rootfs/." "$TARGET_ROOTFS/"
rm -f "$TARGET_ROOTFS/usr/bin/bananarchy-lid.py" \ rm -f "$TARGET_ROOTFS/usr/bin/bananarchy-lid.py" \
"$TARGET_ROOTFS/usr/bin/bananarchy-cover-idle.py" \ "$TARGET_ROOTFS/usr/bin/bananarchy-cover-idle.py" \
"$TARGET_ROOTFS/usr/bin/bananarchy-volume-keys.py" "$TARGET_ROOTFS/usr/bin/bananarchy-volume-keys.py"
for daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do for daemon in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
bananarchy-notifmonitor bananarchy-run-aligned \
bananarchy-session-loop; do
cp -af "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$daemon" \ cp -af "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/$daemon" \
"$TARGET_ROOTFS/usr/bin/$daemon" "$TARGET_ROOTFS/usr/bin/$daemon"
chmod 0755 "$TARGET_ROOTFS/usr/bin/$daemon" chmod 0755 "$TARGET_ROOTFS/usr/bin/$daemon"
@@ -177,6 +184,7 @@ chown 0:0 "$TARGET_ROOTFS/etc/chrony/chrony.conf" \
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \
"$TARGET_ROOTFS/usr/bin/sxmo_run_aligned.sh" \
"$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \ "$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \
@@ -203,6 +211,7 @@ chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-bt-scan.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-bt-le-enable.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-dpm.sh" \
"$TARGET_ROOTFS/usr/bin/sxmo_run_aligned.sh" \
"$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \ "$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" \
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \
+8 -7
View File
@@ -6,7 +6,7 @@ BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SRC_DIR="$BASE_DIR/src/bananarchy-daemons" SRC_DIR="$BASE_DIR/src/bananarchy-daemons"
PREBUILT="$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin" PREBUILT="$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin"
OVERLAY="$BASE_DIR/overlay/rootfs/usr/bin" OVERLAY="$BASE_DIR/overlay/rootfs/usr/bin"
NAMES="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys" NAMES="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor bananarchy-notifmonitor bananarchy-run-aligned bananarchy-session-loop"
check_artifacts() { check_artifacts() {
for name in $NAMES; do for name in $NAMES; do
@@ -58,19 +58,20 @@ EOF
musl-dev-armv7 linux-headers >/dev/null musl-dev-armv7 linux-headers >/dev/null
mkdir -p /bananarchy/prebuilt/bananarchy-daemons/usr/bin \ mkdir -p /bananarchy/prebuilt/bananarchy-daemons/usr/bin \
/bananarchy/overlay/rootfs/usr/bin /bananarchy/overlay/rootfs/usr/bin
for name in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys; do for name in bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys \
bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor \
bananarchy-notifmonitor bananarchy-run-aligned \
bananarchy-session-loop; do
armv7-alpine-linux-musleabihf-gcc -std=c11 -O2 -Wall -Wextra -Werror -s \ armv7-alpine-linux-musleabihf-gcc -std=c11 -O2 -Wall -Wextra -Werror -s \
-I/bananarchy/src/bananarchy-daemons \ -I/bananarchy/src/bananarchy-daemons \
-o "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \ -o "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \
"/bananarchy/src/bananarchy-daemons/$name.c" "/bananarchy/src/bananarchy-daemons/$name.c"
cp -a "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \ cp -a "/bananarchy/prebuilt/bananarchy-daemons/usr/bin/$name" \
"/bananarchy/overlay/rootfs/usr/bin/$name" "/bananarchy/overlay/rootfs/usr/bin/$name"
chown "$HOST_UID:$HOST_GID" \
"/bananarchy/overlay/rootfs/usr/bin/$name"
echo "[+] built $name" echo "[+] built $name"
done done
chown -R "$HOST_UID:$HOST_GID" \ chown -R "$HOST_UID:$HOST_GID" /bananarchy/prebuilt/bananarchy-daemons
/bananarchy/prebuilt/bananarchy-daemons \
/bananarchy/overlay/rootfs/usr/bin/bananarchy-lid \
/bananarchy/overlay/rootfs/usr/bin/bananarchy-cover-idle \
/bananarchy/overlay/rootfs/usr/bin/bananarchy-volume-keys
' '
check_artifacts check_artifacts
+8 -1
View File
@@ -90,10 +90,15 @@ EOF
echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..." echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..."
patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch
fi fi
if ! grep -q "qcom_mpm_enter_sleep" drivers/irqchip/irq-qcom-mpm.c 2>/dev/null; then
echo "[2i/5] Applying MSM8909 RPM LPM, BIMC/WCD/LDO cleanup, and UART disable patch..."
patch -p1 < /bananarchy/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch
fi
if [ ! -f include/config/auto.conf ] || \ if [ ! -f include/config/auto.conf ] || \
! grep -q "CONFIG_NETFILTER_XT_MATCH_OWNER=m" .config 2>/dev/null || \ ! grep -q "CONFIG_NETFILTER_XT_MATCH_OWNER=m" .config 2>/dev/null || \
! grep -q "CONFIG_INTERCONNECT_QCOM_MSM8909=y" .config 2>/dev/null || \ ! grep -q "CONFIG_INTERCONNECT_QCOM_MSM8909=y" .config 2>/dev/null || \
! grep -q "CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y" .config 2>/dev/null; then ! grep -q "CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT=y" .config 2>/dev/null || \
! grep -q "CONFIG_QCOM_RPM_MASTER_STATS=y" .config 2>/dev/null; then
echo "[3/5] Preparing kernel configuration..." echo "[3/5] Preparing kernel configuration..."
cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config
make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- olddefconfig make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- olddefconfig
@@ -129,6 +134,8 @@ EOF
patch -p1 < /bananarchy/patches/kernel/0008-msm8909-standby-power-icc-wifi-usb-panel.patch patch -p1 < /bananarchy/patches/kernel/0008-msm8909-standby-power-icc-wifi-usb-panel.patch
echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..." echo "[2h/5] Applying MSM8909 deep-standby RPM clock, USB PHY, Wi-Fi BET/offload, and DDR patch..."
patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch patch -p1 < /bananarchy/patches/kernel/0009-msm8909-deep-standby-rpm-usb-wifi-ddr.patch
echo "[2i/5] Applying MSM8909 RPM LPM, BIMC/WCD/LDO cleanup, and UART disable patch..."
patch -p1 < /bananarchy/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch
echo "[3/5] Preparing kernel configuration and Module.symvers..." echo "[3/5] Preparing kernel configuration and Module.symvers..."
cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config
+60 -8
View File
@@ -339,6 +339,9 @@ for cmdline_file in "$BASE_DIR"/devices/*/kernel-cmdline.conf \
if grep -qxF 'earlycon' "$cmdline_file"; then if grep -qxF 'earlycon' "$cmdline_file"; then
fail "$(basename "$cmdline_file") still contains earlycon" fail "$(basename "$cmdline_file") still contains earlycon"
fi fi
if grep -qF 'console=ttyMSM0' "$cmdline_file"; then
fail "$(basename "$cmdline_file") still contains console=ttyMSM0"
fi
done done
# A pre-existing rootfs/ build tree is reused by rebuild-image.sh, so its # A pre-existing rootfs/ build tree is reused by rebuild-image.sh, so its
# copies of the device cmdline fragments must stay in sync with the overlay. # copies of the device cmdline fragments must stay in sync with the overlay.
@@ -347,6 +350,9 @@ for cmdline_file in "$BASE_DIR"/rootfs/usr/lib/kernel-cmdline.d/50-device-*.conf
if grep -qxF 'earlycon' "$cmdline_file"; then if grep -qxF 'earlycon' "$cmdline_file"; then
fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains earlycon" fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains earlycon"
fi fi
if grep -qF 'console=ttyMSM0' "$cmdline_file"; then
fail "rootfs/usr/lib/kernel-cmdline.d/$(basename "$cmdline_file") still contains console=ttyMSM0"
fi
done done
echo "[check] BusyBox applet symlinks..." echo "[check] BusyBox applet symlinks..."
@@ -372,9 +378,9 @@ fi
echo "[check] Known-good flashable image set..." echo "[check] Known-good flashable image set..."
for pair in \ for pair in \
"f4c8921a674944b2687b2d7bcb52e6f3cb81ad5997fddac969949305c0479c60 images/bananarchy-nokia-argon.img" \ "77a1201a2a93a076a8dd9a6f11c8ceb5f69b94b2ca7abb3dfeba5354b83c034c images/bananarchy-nokia-argon.img" \
"fd29593b30008b65b7b30b867824ce3f3f4e1f70cda4f012dde1a2c14dd316ba images/bananarchy-nokia-beatles.img" \ "c027c3151f3cf45e7a067beed77d77ff4a1954ababda6f1a2eba5a02b2414b24 images/bananarchy-nokia-beatles.img" \
"d6cb9d5f13bc00815c4fcde5cf32b92ce9d7873683d3cec8b1346a53801ea08a images/boot-bananarchy-nokia-beatles.img" \ "5a7a391aff3fc8fc95b07b532eedce1ee17991574fb45ca4359c0504aeb82324 images/boot-bananarchy-nokia-beatles.img" \
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do "b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
set -- $pair set -- $pair
want=$1 want=$1
@@ -388,7 +394,7 @@ for pair in \
done done
echo "[check] Compiled idle daemons..." echo "[check] Compiled idle daemons..."
DAEMONS="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys" DAEMONS="bananarchy-lid bananarchy-cover-idle bananarchy-volume-keys bananarchy-dsds bananarchy-modemmonitor bananarchy-soundmonitor bananarchy-notifmonitor bananarchy-run-aligned bananarchy-session-loop"
for daemon in $DAEMONS; do for daemon in $DAEMONS; do
for artifact in "prebuilt/bananarchy-daemons/usr/bin/$daemon" \ for artifact in "prebuilt/bananarchy-daemons/usr/bin/$daemon" \
"overlay/rootfs/usr/bin/$daemon"; do "overlay/rootfs/usr/bin/$daemon"; do
@@ -413,7 +419,13 @@ fi
for src in src/bananarchy-daemons/common.h \ for src in src/bananarchy-daemons/common.h \
src/bananarchy-daemons/bananarchy-lid.c \ src/bananarchy-daemons/bananarchy-lid.c \
src/bananarchy-daemons/bananarchy-cover-idle.c \ src/bananarchy-daemons/bananarchy-cover-idle.c \
src/bananarchy-daemons/bananarchy-volume-keys.c; do src/bananarchy-daemons/bananarchy-volume-keys.c \
src/bananarchy-daemons/bananarchy-dsds.c \
src/bananarchy-daemons/bananarchy-modemmonitor.c \
src/bananarchy-daemons/bananarchy-soundmonitor.c \
src/bananarchy-daemons/bananarchy-notifmonitor.c \
src/bananarchy-daemons/bananarchy-run-aligned.c \
src/bananarchy-daemons/bananarchy-session-loop.c; do
if [ ! -f "$BASE_DIR/$src" ]; then if [ ! -f "$BASE_DIR/$src" ]; then
fail "missing C daemon source: $src" fail "missing C daemon source: $src"
fi fi
@@ -1196,21 +1208,61 @@ for dts in \
! grep -qF 'qcom,msm8909-pcnoc' "$dts" || \ ! grep -qF 'qcom,msm8909-pcnoc' "$dts" || \
! grep -qF 'qcom,msm8909-snoc' "$dts" || \ ! grep -qF 'qcom,msm8909-snoc' "$dts" || \
! grep -qF 'interconnects = <0xa0 0x00 0xa0 0x06>;' "$dts" || \ ! grep -qF 'interconnects = <0xa0 0x00 0xa0 0x06>;' "$dts" || \
! grep -qF 'interconnects = <0xa0 0x01 0xa0 0x06>;' "$dts" || \
! grep -qF 'interconnect-names = "gfx-mem";' "$dts" || \
! grep -qF 'opp-peak-kBps = <0x25800>;' "$dts"; then ! grep -qF 'opp-peak-kBps = <0x25800>;' "$dts"; then
fail "${dts#"$BASE_DIR/"} is missing MSM8909 interconnect/OPP bandwidth nodes or 0x25800 floor" fail "${dts#"$BASE_DIR/"} is missing MSM8909 interconnect/GPU-BIMC/OPP bandwidth nodes or 0x25800 floor"
fi fi
done done
if ! grep -qxF 'MODEM_DRX_MODE=6' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \ if ! grep -qxF 'MODEM_DRX_MODE=6' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qxF 'DSDS_SECONDARY_MODE=active' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \ ! grep -qxF 'DSDS_SECONDARY_MODE=active' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qxF 'CPU_RPM_SLEEP=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qxF 'CPU_L2_SLEEP=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qxF 'WIFI_SCREEN_OFF_IPV6_MUTE=1' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qxF 'WIFI_STANDBY_RAT=keep' "$BASE_DIR/overlay/rootfs/etc/bananarchy-power-policy.conf" || \
! grep -qF 'if [ "$port" = "all" ]; then' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \ ! grep -qF 'if [ "$port" = "all" ]; then' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
! grep -qF 'def screen_is_idle():' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \ ! grep -qF 'exec /usr/bin/bananarchy-dsds' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
grep -qF 'dsds-daemon <<' "$BASE_DIR/overlay/rootfs/usr/libexec/msm-modem-uim-selection" || \
! grep -qF 'screen_is_idle(' "$BASE_DIR/src/bananarchy-daemons/bananarchy-dsds.c" || \
! grep -qF 'ExecStart=/usr/bin/bananarchy-modemmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_modemmonitor.service" || \
! grep -qF 'ExecStart=/usr/bin/bananarchy-soundmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_soundmonitor.service" || \
! grep -qF 'ExecStart=/usr/bin/bananarchy-notifmonitor' "$BASE_DIR/overlay/rootfs/usr/share/superd/services/sxmo_notificationmonitor.service" || \
! grep -qF 'exec /usr/bin/bananarchy-run-aligned' "$BASE_DIR/overlay/rootfs/usr/bin/sxmo_run_aligned.sh" || \
! grep -qF 'exec /usr/bin/bananarchy-session-loop' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-x11-session.sh" || \
! grep -qF 'for dev in /dev/wwan0at*;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \ ! grep -qF 'for dev in /dev/wwan0at*;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \
! grep -qF 'modem-ready) modem_ready ;;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \ ! grep -qF 'modem-ready) modem_ready ;;' "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-power-policy.sh" || \
! grep -qF '/usr/bin/bananarchy-power-policy.sh modem-ready' "$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_modem.sh" || \ ! grep -qF '/usr/bin/bananarchy-power-policy.sh modem-ready' "$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_modem.sh" || \
! grep -qF 'WIFI_OFFLOAD_PATH=/sys/module/wcn36xx/parameters/screen_off_offload' \ ! grep -qF 'WIFI_OFFLOAD_PATH=/sys/module/wcn36xx/parameters/screen_off_offload' \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync" || \
! grep -qF 'SPM_SCREEN_OFF_PATH=/sys/module/cpuidle_qcom_spm/parameters/screen_off' \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync"; then "$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-display-power-sync"; then
fail "userspace DSDS DRX, dsds-daemon dark-screen gate, or wcn36xx screen_off_offload sync is missing" fail "userspace DSDS DRX, compiled C daemons, CPU/L2/Wi-Fi power policy, or wcn36xx screen_off_offload sync is missing"
fi fi
if [ ! -f "$BASE_DIR/patches/kernel/0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch" ] || \
! grep -qF '0010-msm8909-rpm-lpm-bimc-wcd-ldo-uart.patch' "$BASE_DIR/scripts/build-kernel-audio.sh" || \
! grep -qxF 'CONFIG_QCOM_RPM_MASTER_STATS=y' "$BASE_DIR/patches/kernel/config-bananarchy-msm8909.armv7" || \
! grep -qxF 'CONFIG_QCOM_RPM_MASTER_STATS=y' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/kernel-config" || \
! grep -q ' qcom_mpm_enter_sleep$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
! grep -q ' spm_get_l2_device$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
! grep -q ' qcom_msm8909_gdsc_is_active$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map" || \
! grep -q ' qcom_iommu_resume$' "$BASE_DIR/prebuilt/kernel-6.12.1-msm8916/System.map"; then
fail "deep-standby kernel patch 0010, RPM master stats config, or vMPM/L2-SAW/IOMMU symbols are missing"
fi
for dts in \
"$BASE_DIR/devices/nokia-argon/qcom-msm8905-nokia-argon.dts" \
"$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts" \
"$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts" \
"$BASE_DIR/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts" \
"$BASE_DIR/devices/nokia-sparkler/qcom-msm8909-nokia-sparkler.dts" \
"$BASE_DIR/devices/nokia-sparkler/qcom-msm8909-nokia-leo.dts"; do
if ! grep -qF 'compatible = "qcom,mpm";' "$dts" || \
! grep -qF 'qcom,msm8909-saw2-v3.0-scu' "$dts" || \
! grep -qF 'compatible = "qcom,msm8916-rpm-stats";' "$dts" || \
! grep -qF 'compatible = "qcom,rpm-master-stats";' "$dts" || \
grep -qF 'stdout-path = "serial0";' "$dts"; then
fail "${dts#"$BASE_DIR/"} is missing vMPM/L2-SAW/RPM-stats nodes or still exposes serial0 console"
fi
done
if ! grep -qF -- '--dpm-open-port=' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \ if ! grep -qF -- '--dpm-open-port=' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \
grep -qF '_need_dpm' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \ grep -qF '_need_dpm' "$BASE_DIR/overlay/rootfs/etc/init.d/msm8909-modem-wwan-port" || \
grep -qF 'bananarchy-dpm.sh close' "$BASE_DIR/overlay/rootfs/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" || \ grep -qF 'bananarchy-dpm.sh close' "$BASE_DIR/overlay/rootfs/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh" || \
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env python3
"""Host selftest for the compiled C DSDS and session daemons."""
import os
import subprocess
import tempfile
import unittest
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC_DIR = os.path.join(BASE_DIR, "src", "bananarchy-daemons")
def encode_gsm7_with_fill(text, udh=b""):
septets = []
ext_map = {
"\f": 0x0A, "^": 0x14, "{": 0x28, "}": 0x29, "\\": 0x2F,
"[": 0x3C, "~": 0x3D, "]": 0x3E, "|": 0x40, "\u20ac": 0x65,
}
basic = (
"@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5"
"\u0394_\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\x1b\u00c6\u00e6\u00df\u00c9"
" !\"#\u00a4%&'()*+,-./0123456789:;<=>?"
"\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6\u00d1\u00dc\u00a7"
"\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1\u00fc\u00e0"
)
for ch in text:
if ch in ext_map:
septets.append(0x1B)
septets.append(ext_map[ch])
else:
septets.append(basic.index(ch))
fill_bits = (7 - ((len(udh) * 8) % 7)) % 7 if udh else 0
start_septet = ((len(udh) * 8) + fill_bits) // 7
udl = start_septet + len(septets)
packed_len = (udl * 7 + 7) // 8
buf = bytearray(max(len(udh), packed_len))
buf[:len(udh)] = udh
for idx, val in enumerate(septets):
sidx = start_septet + idx
bit_off = sidx * 7
bidx = bit_off // 8
sh = bit_off % 8
buf[bidx] |= (val << sh) & 0xFF
if sh > 1:
buf[bidx + 1] |= (val >> (8 - sh)) & 0xFF
return udl, bytes(buf)
def build_deliver_pdu(oa_digits, oa_ton_npi, oa_bytes, dcs, udl, ud,
udh=False, smsc=b"\x00"):
fo = 0x40 if udh else 0x00
scts = bytes([0x62, 0x11, 0x31, 0x61, 0x03, 0x00, 0x08])
tpdu = bytearray([fo, oa_digits, oa_ton_npi]) + oa_bytes + bytes([0x00, dcs]) + scts + bytes([udl]) + ud
return (smsc + bytes(tpdu)).hex()
class DsdsDaemonTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmpdir = tempfile.TemporaryDirectory()
cls.bin = os.path.join(cls.tmpdir.name, "dsds_selftest")
subprocess.run(
[
"gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-DBANANARCHY_DSDS_SELFTEST",
"-I", SRC_DIR,
"-o", cls.bin,
os.path.join(SRC_DIR, "bananarchy-dsds.c"),
],
check=True,
)
@classmethod
def tearDownClass(cls):
cls.tmpdir.cleanup()
def test_all_c_daemons_host_compile_cleanly(self):
for name in [
"bananarchy-dsds.c",
"bananarchy-modemmonitor.c",
"bananarchy-soundmonitor.c",
"bananarchy-notifmonitor.c",
"bananarchy-run-aligned.c",
"bananarchy-session-loop.c",
]:
out = os.path.join(self.tmpdir.name, name + ".bin")
subprocess.run(
[
"gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I", SRC_DIR, "-o", out, os.path.join(SRC_DIR, name),
],
check=True,
)
def test_gsm7_and_ext_and_international_oa(self):
udl, ud = encode_gsm7_with_fill("Price: 10\u20ac [ok]")
# +358401234567 -> 12 digits, TON=1 NPI=1 (0x91)
oa = bytes.fromhex("534810325476")
pdu = build_deliver_pdu(12, 0x91, oa, 0x00, udl, ud)
res = subprocess.run([self.bin, pdu], capture_output=True, text=True, check=True)
self.assertIn("DELIVER\t2\t+358401234567\tPrice: 10\u20ac [ok]\n", res.stdout)
def test_alphanumeric_sender_and_ucs2_surrogate(self):
# Alphanumeric "Nokia" (5 chars -> 35 bits -> 9 hex digits rounded up = 9 nibbles)
_, oa = encode_gsm7_with_fill("Nokia")
oa_digits = (len("Nokia") * 7 + 3) // 4
payload = "Hi \U0001F34C".encode("utf-16-be")
pdu = "tpdu:" + build_deliver_pdu(
oa_digits, 0xD0, oa, 0x08, len(payload), payload, smsc=b""
)
res = subprocess.run([self.bin, pdu], capture_output=True, text=True, check=True)
self.assertIn("DELIVER\t2\tNokia\tHi \U0001F34C\n", res.stdout)
def test_multipart_csms_out_of_order_and_dedup(self):
oa = bytes.fromhex("534810325476")
udh1 = bytes([0x05, 0x00, 0x03, 0x2A, 0x02, 0x01])
udh2 = bytes([0x06, 0x08, 0x04, 0x00, 0x2A, 0x02, 0x02])
# Use matching 8-bit CSMS ref 0x2A across both parts
udh2_8 = bytes([0x05, 0x00, 0x03, 0x2A, 0x02, 0x02])
u1, d1 = encode_gsm7_with_fill("Hello ", udh1)
u2, d2 = encode_gsm7_with_fill("World!", udh2_8)
pdu1 = build_deliver_pdu(12, 0x91, oa, 0x00, u1, d1, udh=True)
pdu2 = build_deliver_pdu(12, 0x91, oa, 0x00, u2, d2, udh=True)
res = subprocess.run(
[self.bin, pdu2, pdu1, pdu1],
capture_output=True, text=True, check=True,
)
delivers = [ln for ln in res.stdout.splitlines() if ln.startswith("DELIVER\t")]
self.assertEqual(delivers, ["DELIVER\t2\t+358401234567\tHello World!"])
# Also verify 16-bit CSMS UDH IEI 0x08 in UCS-2
udh16_1 = bytes([0x06, 0x08, 0x04, 0x12, 0x34, 0x02, 0x01])
udh16_2 = bytes([0x06, 0x08, 0x04, 0x12, 0x34, 0x02, 0x02])
p1 = udh16_1 + "One ".encode("utf-16-be")
p2 = udh16_2 + "Two".encode("utf-16-be")
q1 = build_deliver_pdu(12, 0x91, oa, 0x08, len(p1), p1, udh=True)
q2 = build_deliver_pdu(12, 0x91, oa, 0x08, len(p2), p2, udh=True)
_ = udh2
res2 = subprocess.run([self.bin, q1, q2], capture_output=True, text=True, check=True)
self.assertIn("DELIVER\t2\t+358401234567\tOne Two\n", res2.stdout)
if __name__ == "__main__":
unittest.main()
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,908 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Compiled ModemManager D-Bus monitor & DSDS supervisor replacing sxmo_modemmonitor.sh. */
#include <dirent.h>
#include <limits.h>
#include <poll.h>
#include <regex.h>
#include "common.h"
static volatile sig_atomic_t stop_requested = 0;
static volatile pid_t mm_pid = -1;
static volatile pid_t mms_pid = -1;
static volatile pid_t vvm_pid = -1;
static volatile pid_t dsds_pid = -1;
static int sig_pipe[2] = { -1, -1 };
static void handle_stop(int sig)
{
(void)sig;
stop_requested = 1;
if(sig_pipe[1] >= 0) {
char b = 'q';
ssize_t r = write(sig_pipe[1], &b, 1);
(void)r;
}
}
static void handle_sigchld(int sig)
{
(void)sig;
if(sig_pipe[1] >= 0) {
char b = 'c';
ssize_t r = write(sig_pipe[1], &b, 1);
(void)r;
}
}
static void spawn_detached(char *const argv[])
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static void run_sync_quiet(char *const argv[])
{
pid_t pid = fork();
int st = 0;
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
if(pid > 0) {
while(waitpid(pid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static int run_capture(char *const argv[], char *out, size_t out_len)
{
int pfd[2];
pid_t pid;
size_t total = 0;
int st = 0;
if(!out || out_len == 0)
return -1;
out[0] = '\0';
if(pipe2(pfd, O_CLOEXEC) < 0)
return -1;
pid = fork();
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
if(pfd[1] > STDERR_FILENO)
close(pfd[1]);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
close(pfd[1]);
if(pid < 0) {
close(pfd[0]);
return -1;
}
while(total < out_len - 1) {
ssize_t n = read(pfd[0], out + total, out_len - 1 - total);
if(n > 0) {
total += (size_t)n;
continue;
}
if(n < 0 && errno == EINTR)
continue;
break;
}
out[total] = '\0';
close(pfd[0]);
while(waitpid(pid, &st, 0) < 0 && errno == EINTR) {
}
return WIFEXITED(st) ? WEXITSTATUS(st) : -1;
}
static void resolve_notifdir(char *out, size_t len)
{
const char *env_dir = getenv("SXMO_NOTIFDIR");
const char *xdg_data = getenv("XDG_DATA_HOME");
const char *home = getenv("HOME");
if(env_dir && *env_dir && strcmp(env_dir, "/") != 0) {
safe_copy(out, len, env_dir);
return;
}
if(xdg_data && *xdg_data) {
snprintf(out, len, "%s/sxmo/notifications", xdg_data);
return;
}
snprintf(out, len, "%s/.local/share/sxmo/notifications",
(home && *home) ? home : "/home/user");
}
static void cleanup_session_files(void)
{
const char *xdg_rt = getenv("XDG_RUNTIME_DIR");
const char *rt = (xdg_rt && *xdg_rt) ? xdg_rt : "/run/user/10000";
char dir_path[PATH_MAX];
char notif_dir[PATH_MAX];
DIR *dir;
struct dirent *de;
snprintf(dir_path, sizeof(dir_path), "%s/sxmo_calls", rt);
dir = opendir(dir_path);
if(dir) {
while((de = readdir(dir)) != NULL) {
if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
continue;
unlinkat(dirfd(dir), de->d_name, 0);
}
closedir(dir);
}
snprintf(dir_path, sizeof(dir_path), "%s/sxmo.ring.pid", rt);
unlink(dir_path);
resolve_notifdir(notif_dir, sizeof(notif_dir));
dir = opendir(notif_dir);
if(dir) {
while((de = readdir(dir)) != NULL) {
if(strncmp(de->d_name, "incomingcall", 12) != 0)
continue;
unlinkat(dirfd(dir), de->d_name, 0);
}
closedir(dir);
}
}
static const char *statenum_to_name(const char *s)
{
while(*s == ' ' || *s == '\t')
s++;
if(strcmp(s, "int32 -1") == 0) return "failed";
if(strcmp(s, "int32 0") == 0) return "unknown";
if(strcmp(s, "int32 1") == 0) return "initializing";
if(strcmp(s, "int32 2") == 0) return "locked";
if(strcmp(s, "int32 3") == 0) return "disabled";
if(strcmp(s, "int32 4") == 0) return "disabling";
if(strcmp(s, "int32 5") == 0) return "enabling";
if(strcmp(s, "int32 6") == 0) return "enabled";
if(strcmp(s, "int32 7") == 0) return "searching";
if(strcmp(s, "int32 8") == 0) return "registered";
if(strcmp(s, "int32 9") == 0) return "disconnecting";
if(strcmp(s, "int32 10") == 0) return "connecting";
if(strcmp(s, "int32 11") == 0) return "connected";
return "ERROR";
}
static void get_mm_state(char *out, size_t len)
{
char raw[4096];
char *line;
char *save = NULL;
char *const argv[] = {
(char *)"mmcli", (char *)"-m", (char *)"any", (char *)"-K", NULL
};
out[0] = '\0';
if(run_capture(argv, raw, sizeof(raw)) != 0)
return;
for(line = strtok_r(raw, "\n", &save); line; line = strtok_r(NULL, "\n", &save)) {
if(strncmp(line, "modem.generic.state ", 20) == 0) {
char *colon = strchr(line, ':');
if(colon) {
colon++;
while(*colon == ' ' || *colon == '\t')
colon++;
safe_copy(out, len, colon);
}
break;
}
}
}
static int grep_regex(const char *text, const char *pattern)
{
regex_t re;
int rc;
if(regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0)
return 0;
rc = regexec(&re, text, 0, NULL, 0);
regfree(&re);
return rc == 0;
}
static void spawn_uim_cmd(const char *subcmd, char *out, size_t out_len)
{
if(geteuid() == 0) {
char *const argv[] = {
(char *)"/usr/libexec/msm-modem-uim-selection", (char *)subcmd, NULL
};
if(out)
run_capture(argv, out, out_len);
else
run_sync_quiet(argv);
} else {
char *const argv[] = {
(char *)"doas", (char *)"-n",
(char *)"/usr/libexec/msm-modem-uim-selection", (char *)subcmd, NULL
};
if(out)
run_capture(argv, out, out_len);
else
run_sync_quiet(argv);
}
}
static void spawn_boot_probe(void)
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
char newstate[64] = "";
char uim_st[2048] = "";
int tries;
for(tries = 0; tries < 15; tries++) {
get_mm_state(newstate, sizeof(newstate));
if(newstate[0] != '\0')
break;
sleep(2);
}
spawn_uim_cmd("status", uim_st, sizeof(uim_st));
if(grep_regex(uim_st,
"SLOT[12]_PIN1_STATE=(enabled-not-verified|blocked)|"
"SLOT[12]_APP_STATE=(pin1|puk1)")) {
safe_copy(newstate, sizeof(newstate), "locked");
} else if(strcmp(newstate, "locked") == 0 &&
grep_regex(uim_st, "^MODEM_AVAILABLE=1$")) {
get_mm_state(newstate, sizeof(newstate));
if(strcmp(newstate, "locked") == 0)
safe_copy(newstate, sizeof(newstate), "disabled");
} else if(grep_regex(uim_st, "SLOT[12]_STATE=present") &&
grep_regex(uim_st, "^PRIMARY_GW_SLOT=0$")) {
spawn_uim_cmd("boot", NULL, 0);
get_mm_state(newstate, sizeof(newstate));
} else if(grep_regex(uim_st, "^SLOT1_STATE=present$") &&
grep_regex(uim_st, "^SLOT2_STATE=present$") &&
grep_regex(uim_st, "^SECONDARY_GW_SLOT=0$")) {
spawn_uim_cmd("boot", NULL, 0);
}
if(newstate[0] != '\0') {
char *const hook_argv[] = {
(char *)"sxmo_hook_modem.sh", (char *)"boot",
newstate, (char *)"0", NULL
};
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"modem", NULL
};
run_sync_quiet(hook_argv);
run_sync_quiet(sb_argv);
}
_exit(0);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static void dispatch_modem_state_async(const char *oldstate,
const char *newstate,
const char *reason)
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
char old_copy[64];
char new_copy[64];
char reason_copy[64];
const char *p = reason;
if(strncmp(p, "uint32 ", 7) == 0)
p += 7;
safe_copy(old_copy, sizeof(old_copy), oldstate);
safe_copy(new_copy, sizeof(new_copy), newstate);
safe_copy(reason_copy, sizeof(reason_copy), p);
{
char *const hook_argv[] = {
(char *)"sxmo_hook_modem.sh", old_copy, new_copy, reason_copy, NULL
};
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"modem", NULL
};
run_sync_quiet(hook_argv);
run_sync_quiet(sb_argv);
}
_exit(0);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static int start_dbus_pipe(char *const argv[], volatile pid_t *out_pid)
{
int pfd[2];
pid_t pid;
if(pipe2(pfd, O_NONBLOCK | O_CLOEXEC) < 0)
return -1;
pid = fork();
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
if(pfd[1] > STDERR_FILENO)
close(pfd[1]);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
close(pfd[1]);
if(pid < 0) {
close(pfd[0]);
return -1;
}
*out_pid = pid;
return pfd[0];
}
struct mm_parser {
int state_stage;
char old_line[128];
char new_line[128];
char cur_modem[128];
};
static void mm_process_line(struct mm_parser *mp, const char *line)
{
if(mp->state_stage == 1) {
safe_copy(mp->old_line, sizeof(mp->old_line), line);
mp->state_stage = 2;
return;
}
if(mp->state_stage == 2) {
safe_copy(mp->new_line, sizeof(mp->new_line), line);
mp->state_stage = 3;
return;
}
if(mp->state_stage == 3) {
mp->state_stage = 0;
dispatch_modem_state_async(statenum_to_name(mp->old_line),
statenum_to_name(mp->new_line), line);
return;
}
if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "interface=org.freedesktop.ModemManager1.Modem.Voice") &&
strstr(line, "member=CallAdded")) {
char *const argv[] = {
(char *)"sxmo_modem.sh", (char *)"checkforincomingcalls", NULL
};
spawn_detached(argv);
} else if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "interface=org.freedesktop.ModemManager1.Modem.Messaging") &&
strstr(line, "member=Added")) {
char *const argv[] = {
(char *)"sxmo_modem.sh", (char *)"checkfornewtexts", NULL
};
spawn_detached(argv);
} else if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "path=/org/freedesktop/ModemManager1/SMS/") &&
strstr(line, "member=PropertiesChanged")) {
char *const argv[] = {
(char *)"sxmo_modem.sh", (char *)"checkfornewtexts", NULL
};
spawn_detached(argv);
} else if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "path=/org/freedesktop/ModemManager1/Call/") &&
strstr(line, "member=PropertiesChanged")) {
char *const argv[] = {
(char *)"sxmo_modem.sh", (char *)"checkforfinishedcalls", NULL
};
spawn_detached(argv);
} else if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "interface=org.freedesktop.ModemManager1.Modem;") &&
strstr(line, "member=StateChanged")) {
mp->state_stage = 1;
} else if(strncmp(line, "signal", 6) == 0 &&
strstr(line, "path=/org/freedesktop/ModemManager1/Modem/") &&
strstr(line, "member=PropertiesChanged")) {
const char *p = strstr(line, "path=");
if(p) {
const char *semi;
p += 5;
semi = strchr(p, ';');
if(semi && (size_t)(semi - p) < sizeof(mp->cur_modem)) {
memcpy(mp->cur_modem, p, (size_t)(semi - p));
mp->cur_modem[semi - p] = '\0';
}
}
} else if(strstr(line, "string \"NetworkNotification\"") &&
mp->cur_modem[0] != '\0') {
char *const argv[] = {
(char *)"sxmo_ussd.sh", mp->cur_modem,
(char *)"NetworkNotification", (char *)"", NULL
};
spawn_detached(argv);
} else if(strstr(line, "string \"NetworkRequest\"") &&
mp->cur_modem[0] != '\0') {
char *const argv[] = {
(char *)"sxmo_ussd.sh", mp->cur_modem,
(char *)"NetworkRequest", (char *)"", NULL
};
spawn_detached(argv);
}
}
struct aux_parser {
char mms_path[256];
int vvm_start;
char vvm_date[128];
char vvm_sender[128];
char vvm_id[128];
char vvm_attach[256];
};
static void extract_quoted(const char *line, char *out, size_t len)
{
const char *q1 = strchr(line, '"');
const char *q2 = q1 ? strchr(q1 + 1, '"') : NULL;
if(!q1 || !q2 || q2 <= q1 + 1) {
out[0] = '\0';
return;
}
{
size_t n = (size_t)(q2 - q1 - 1);
if(n >= len)
n = len - 1;
memcpy(out, q1 + 1, n);
out[n] = '\0';
}
}
static void mms_process_line(struct aux_parser *ap, const char *line)
{
const char *p = line;
while(*p == ' ' || *p == '\t')
p++;
if(strncmp(p, "object path", 11) == 0) {
extract_quoted(p, ap->mms_path, sizeof(ap->mms_path));
} else if(strstr(p, "string \"received\"") && ap->mms_path[0] != '\0') {
char *const argv[] = {
(char *)"sxmo_mms.sh", (char *)"processmms", ap->mms_path, NULL
};
spawn_detached(argv);
}
}
static void vvm_process_line(struct aux_parser *ap, const char *line)
{
static int vvm_field = 0;
const char *p = line;
while(*p == ' ' || *p == '\t')
p++;
if(vvm_field == 1) {
extract_quoted(p, ap->vvm_date, sizeof(ap->vvm_date));
vvm_field = 0;
return;
}
if(vvm_field == 2) {
extract_quoted(p, ap->vvm_sender, sizeof(ap->vvm_sender));
vvm_field = 0;
return;
}
if(vvm_field == 3) {
extract_quoted(p, ap->vvm_attach, sizeof(ap->vvm_attach));
vvm_field = 0;
return;
}
if(strncmp(p, "object path", 11) == 0) {
char obj[256];
const char *slash;
extract_quoted(p, obj, sizeof(obj));
slash = strrchr(obj, '/');
safe_copy(ap->vvm_id, sizeof(ap->vvm_id), slash ? slash + 1 : obj);
ap->vvm_start = 1;
} else if(p[0] == ']') {
ap->vvm_start = 0;
{
char *const argv[] = {
(char *)"sxmo_vvm.sh", (char *)"processvvm",
ap->vvm_date, ap->vvm_sender, ap->vvm_id, ap->vvm_attach, NULL
};
spawn_detached(argv);
}
} else if(ap->vvm_start) {
if(strncmp(p, "string \"Date\"", 13) == 0)
vvm_field = 1;
else if(strncmp(p, "string \"Sender\"", 15) == 0)
vvm_field = 2;
else if(strncmp(p, "string \"Attachments\"", 20) == 0)
vvm_field = 3;
}
}
typedef void (*line_cb_fn)(void *ctx, const char *line);
static int drain_pipe_lines(int fd, char *buf, size_t buf_cap, size_t *len,
line_cb_fn cb, void *ctx)
{
for(;;) {
ssize_t n;
char *nl;
if(*len >= buf_cap - 1)
*len = 0;
n = read(fd, buf + *len, buf_cap - 1 - *len);
if(n > 0) {
*len += (size_t)n;
buf[*len] = '\0';
while((nl = strchr(buf, '\n')) != NULL) {
size_t rest;
*nl = '\0';
cb(ctx, buf);
rest = (size_t)(buf + *len - (nl + 1));
memmove(buf, nl + 1, rest);
*len = rest;
buf[*len] = '\0';
}
continue;
}
if(n == 0 || (errno != EAGAIN && errno != EWOULDBLOCK))
return -1;
break;
}
return 0;
}
static int dsds_lock_held(void)
{
int fd = open("/tmp/dsds_daemon.lock", O_RDONLY | O_CLOEXEC);
int held = 0;
if(fd < 0)
return 0;
if(flock(fd, LOCK_EX | LOCK_NB) < 0) {
if(errno == EWOULDBLOCK || errno == EAGAIN)
held = 1;
} else {
flock(fd, LOCK_UN);
}
close(fd);
return held;
}
static void maybe_start_dsds(long long *due_ms)
{
char active[16] = "";
if(access("/tmp/sxmo_dsds_active", F_OK) != 0)
spawn_uim_cmd("status", NULL, 0);
if(read_first_line("/tmp/sxmo_dsds_active", active, sizeof(active)) != 0 ||
strcmp(active, "1") != 0) {
*due_ms = -1;
return;
}
if(dsds_pid > 0) {
*due_ms = -1;
return;
}
if(dsds_lock_held()) {
*due_ms = now_ms() + 30000;
return;
}
{
pid_t pid = fork();
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
if(geteuid() == 0) {
execl("/usr/bin/bananarchy-dsds", "bananarchy-dsds", (char *)NULL);
} else {
execlp("doas", "doas", "-n", "/usr/bin/bananarchy-dsds", (char *)NULL);
}
_exit(127);
}
if(pid > 0) {
dsds_pid = pid;
*due_ms = -1;
} else {
*due_ms = now_ms() + 30000;
}
}
}
int main(void)
{
struct sigaction sa;
const char *home = getenv("HOME");
char mms_flag[PATH_MAX];
char vvm_flag[PATH_MAX];
int mm_fd;
int mms_fd = -1;
int vvm_fd = -1;
int tmp_ifd;
int wd = -1;
char mm_buf[4096];
char mms_buf[2048];
char vvm_buf[2048];
size_t mm_len = 0;
size_t mms_len = 0;
size_t vvm_len = 0;
struct mm_parser mp;
struct aux_parser ap;
long long dsds_due_ms;
memset(&mp, 0, sizeof(mp));
memset(&ap, 0, sizeof(ap));
if(pipe2(sig_pipe, O_NONBLOCK | O_CLOEXEC) < 0)
return 1;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_stop;
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sa.sa_handler = handle_sigchld;
sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
sigaction(SIGCHLD, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
cleanup_session_files();
spawn_boot_probe();
{
char *const mm_argv[] = {
(char *)"dbus-monitor", (char *)"--system",
(char *)"interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'",
(char *)"interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'",
(char *)"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Sms'",
(char *)"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'",
(char *)"interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'",
(char *)"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd'",
NULL
};
mm_fd = start_dbus_pipe(mm_argv, &mm_pid);
}
snprintf(mms_flag, sizeof(mms_flag), "%s/.mms/modemmanager/mms",
(home && *home) ? home : "/home/user");
if(access(mms_flag, F_OK) == 0) {
char *const mms_argv[] = {
(char *)"dbus-monitor",
(char *)"interface='org.ofono.mms.Service',type='signal',member='MessageAdded'",
NULL
};
mms_fd = start_dbus_pipe(mms_argv, &mms_pid);
}
snprintf(vvm_flag, sizeof(vvm_flag), "%s/.vvm/modemmanager/vvm",
(home && *home) ? home : "/home/user");
if(access(vvm_flag, F_OK) == 0) {
char *const vvm_argv[] = {
(char *)"dbus-monitor",
(char *)"interface='org.kop316.vvm.Service',type='signal',member='MessageAdded'",
NULL
};
vvm_fd = start_dbus_pipe(vvm_argv, &vvm_pid);
}
tmp_ifd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if(tmp_ifd >= 0) {
wd = inotify_add_watch(tmp_ifd, "/tmp",
IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_DELETE);
(void)wd;
}
dsds_due_ms = now_ms() + 4000;
while(!stop_requested) {
struct pollfd fds[5];
int nfds = 0;
int idx_sig = -1, idx_mm = -1, idx_mms = -1, idx_vvm = -1, idx_tmp = -1;
int timeout_ms = -1;
long long now = now_ms();
idx_sig = nfds;
fds[nfds].fd = sig_pipe[0];
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
if(mm_fd >= 0) {
idx_mm = nfds;
fds[nfds].fd = mm_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(mms_fd >= 0) {
idx_mms = nfds;
fds[nfds].fd = mms_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(vvm_fd >= 0) {
idx_vvm = nfds;
fds[nfds].fd = vvm_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(tmp_ifd >= 0) {
idx_tmp = nfds;
fds[nfds].fd = tmp_ifd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(dsds_due_ms >= 0) {
long long rem = dsds_due_ms - now;
timeout_ms = (rem > 0) ? (int)rem : 0;
}
if(poll(fds, (nfds_t)nfds, timeout_ms) < 0) {
if(errno == EINTR)
continue;
break;
}
if(stop_requested)
break;
if(idx_sig >= 0 && (fds[idx_sig].revents & POLLIN)) {
char sbuf[64];
int st;
while(read(sig_pipe[0], sbuf, sizeof(sbuf)) > 0) {
}
if(dsds_pid > 0 && waitpid(dsds_pid, &st, WNOHANG) > 0) {
char active[16] = "";
dsds_pid = -1;
if(read_first_line("/tmp/sxmo_dsds_active", active, sizeof(active)) == 0 &&
strcmp(active, "1") == 0) {
dsds_due_ms = now_ms() + 30000;
}
}
if(mm_pid > 0 && waitpid(mm_pid, &st, WNOHANG) > 0)
mm_pid = -1;
if(mms_pid > 0 && waitpid(mms_pid, &st, WNOHANG) > 0)
mms_pid = -1;
if(vvm_pid > 0 && waitpid(vvm_pid, &st, WNOHANG) > 0)
vvm_pid = -1;
}
if(idx_mm >= 0 && (fds[idx_mm].revents & (POLLIN | POLLERR | POLLHUP))) {
if(drain_pipe_lines(mm_fd, mm_buf, sizeof(mm_buf), &mm_len,
(line_cb_fn)mm_process_line, &mp) < 0) {
close(mm_fd);
mm_fd = -1;
break;
}
}
if(idx_mms >= 0 && (fds[idx_mms].revents & (POLLIN | POLLERR | POLLHUP))) {
if(drain_pipe_lines(mms_fd, mms_buf, sizeof(mms_buf), &mms_len,
(line_cb_fn)mms_process_line, &ap) < 0) {
close(mms_fd);
mms_fd = -1;
}
}
if(idx_vvm >= 0 && (fds[idx_vvm].revents & (POLLIN | POLLERR | POLLHUP))) {
if(drain_pipe_lines(vvm_fd, vvm_buf, sizeof(vvm_buf), &vvm_len,
(line_cb_fn)vvm_process_line, &ap) < 0) {
close(vvm_fd);
vvm_fd = -1;
}
}
if(idx_tmp >= 0 && (fds[idx_tmp].revents & POLLIN)) {
char ibuf[4096];
ssize_t n;
while((n = read(tmp_ifd, ibuf, sizeof(ibuf))) > 0) {
ssize_t off = 0;
while(off < n) {
const struct inotify_event *ev =
(const struct inotify_event *)(ibuf + off);
if(ev->len > 0 && strcmp(ev->name, "sxmo_dsds_active") == 0) {
char active[16] = "";
if(read_first_line("/tmp/sxmo_dsds_active", active, sizeof(active)) == 0 &&
strcmp(active, "1") == 0) {
if(dsds_pid <= 0)
dsds_due_ms = now_ms() + 200;
} else {
dsds_due_ms = -1;
}
}
off += (ssize_t)(sizeof(*ev) + ev->len);
}
}
}
if(dsds_due_ms >= 0 && now_ms() >= dsds_due_ms)
maybe_start_dsds(&dsds_due_ms);
}
if(mm_pid > 0) {
int st;
kill(mm_pid, SIGTERM);
waitpid(mm_pid, &st, 0);
}
if(mms_pid > 0) {
int st;
kill(mms_pid, SIGTERM);
waitpid(mms_pid, &st, 0);
}
if(vvm_pid > 0) {
int st;
kill(vvm_pid, SIGTERM);
waitpid(vvm_pid, &st, 0);
}
if(dsds_pid > 0) {
int st;
kill(dsds_pid, SIGTERM);
waitpid(dsds_pid, &st, 0);
}
if(mm_fd >= 0) close(mm_fd);
if(mms_fd >= 0) close(mms_fd);
if(vvm_fd >= 0) close(vvm_fd);
if(tmp_ifd >= 0) close(tmp_ifd);
close(sig_pipe[0]);
close(sig_pipe[1]);
return 0;
}
@@ -0,0 +1,346 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Compiled notification monitor replacing sxmo_notifs.sh monitor. */
#include <dirent.h>
#include <limits.h>
#include <poll.h>
#include "common.h"
static volatile sig_atomic_t stop_requested = 0;
static void handle_signal(int sig)
{
(void)sig;
stop_requested = 1;
}
static void spawn_detached(char *const argv[])
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static void mkdir_p(const char *path)
{
char buf[PATH_MAX];
char *p;
safe_copy(buf, sizeof(buf), path);
for(p = buf + 1; *p; p++) {
if(*p == '/') {
*p = '\0';
mkdir(buf, 0755);
*p = '/';
}
}
mkdir(buf, 0755);
}
static void resolve_notifdir(char *out, size_t len)
{
const char *env_dir = getenv("SXMO_NOTIFDIR");
const char *xdg_data = getenv("XDG_DATA_HOME");
const char *home = getenv("HOME");
if(env_dir && *env_dir && strcmp(env_dir, "/") != 0) {
safe_copy(out, len, env_dir);
return;
}
if(xdg_data && *xdg_data) {
snprintf(out, len, "%s/sxmo/notifications", xdg_data);
return;
}
snprintf(out, len, "%s/.local/share/sxmo/notifications",
(home && *home) ? home : "/home/user");
}
static void strip_eol(char *s)
{
size_t n = strlen(s);
while(n > 0 && (s[n - 1] == '\n' || s[n - 1] == '\r'))
s[--n] = '\0';
}
static void clear_notif_group(const char *notifdir, const char *group)
{
DIR *dir;
struct dirent *de;
if(!group || !*group)
return;
dir = opendir(notifdir);
if(!dir)
return;
while((de = readdir(dir)) != NULL) {
char path[PATH_MAX];
char line[512];
struct stat st;
if(de->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", notifdir, de->d_name);
if(stat(path, &st) < 0 || !S_ISREG(st.st_mode))
continue;
if(read_first_line(path, line, sizeof(line)) == 0 &&
strcmp(line, group) == 0) {
unlink(path);
}
}
closedir(dir);
}
static void notifications_hook(const char *notifdir)
{
DIR *dir = opendir(notifdir);
struct dirent *de;
int count = 0;
char count_str[32];
if(dir) {
while((de = readdir(dir)) != NULL) {
char path[PATH_MAX];
struct stat st;
if(de->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", notifdir, de->d_name);
if(stat(path, &st) == 0 && S_ISREG(st.st_mode))
count++;
}
closedir(dir);
}
snprintf(count_str, sizeof(count_str), "%d", count);
{
char *const argv[] = {
(char *)"sxmo_hook_notifications.sh", count_str, NULL
};
spawn_detached(argv);
}
}
static void run_dunstify_worker(const char *notifdir, const char *group,
const char *action, const char *msg)
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
int pipefd[2];
pid_t dpid;
char out[128] = "";
ssize_t total = 0;
if(pipe2(pipefd, O_CLOEXEC) < 0)
_exit(1);
dpid = fork();
if(dpid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
close(pipefd[0]);
dup2(pipefd[1], STDOUT_FILENO);
if(pipefd[1] > STDERR_FILENO)
close(pipefd[1]);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execlp("dunstify", "dunstify", "--action=default,Open", msg, (char *)NULL);
_exit(127);
}
close(pipefd[1]);
if(dpid > 0) {
ssize_t n;
int st;
while(total < (ssize_t)sizeof(out) - 1 &&
(n = read(pipefd[0], out + total, sizeof(out) - 1 - (size_t)total)) > 0) {
total += n;
}
out[total] = '\0';
while(waitpid(dpid, &st, 0) < 0 && errno == EINTR) {
}
}
close(pipefd[0]);
strip_eol(out);
if(strcmp(out, "default") == 0) {
clear_notif_group(notifdir, group);
{
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"notifications", NULL
};
spawn_detached(sb_argv);
}
if(action[0] != '\0' && strcmp(action, "none") != 0) {
char *const act_argv[] = {
(char *)"/bin/sh", (char *)"-c", (char *)action, NULL
};
spawn_detached(act_argv);
}
}
_exit(0);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static void handle_new_notif_file(const char *notifdir, const char *path,
int is_boot)
{
const char *base = strrchr(path, '/');
struct stat st;
FILE *f;
char group[512] = "";
char action[1024] = "";
char msg[256] = "";
int nl_count = 0;
int ch;
size_t msg_len = 0;
base = base ? base + 1 : path;
if(base[0] == '.')
return;
if(stat(path, &st) < 0 || !S_ISREG(st.st_mode))
return;
f = fopen(path, "r");
if(!f)
return;
while((ch = fgetc(f)) != EOF) {
if(ch == '\n')
nl_count++;
}
if(nl_count < 3) {
fclose(f);
unlink(path);
return;
}
rewind(f);
if(!fgets(group, sizeof(group), f))
group[0] = '\0';
if(!fgets(action, sizeof(action), f))
action[0] = '\0';
while(msg_len < 70 && (ch = fgetc(f)) != EOF) {
if(ch == '\r')
continue;
if(ch == '\n') {
if(msg_len > 0)
break;
continue;
}
msg[msg_len++] = (char)ch;
}
msg[msg_len] = '\0';
fclose(f);
strip_eol(group);
strip_eol(action);
if(!is_boot) {
char path_copy[PATH_MAX];
safe_copy(path_copy, sizeof(path_copy), path);
char *const hook_argv[] = {
(char *)"sxmo_hook_notification.sh", path_copy, NULL
};
spawn_detached(hook_argv);
}
run_dunstify_worker(notifdir, group, action, msg);
}
int main(void)
{
char notifdir[PATH_MAX];
int ifd;
DIR *dir;
struct dirent *de;
struct sigaction sa;
struct pollfd pfd;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
resolve_notifdir(notifdir, sizeof(notifdir));
mkdir_p(notifdir);
dir = opendir(notifdir);
if(dir) {
while((de = readdir(dir)) != NULL) {
char path[PATH_MAX];
if(de->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", notifdir, de->d_name);
handle_new_notif_file(notifdir, path, 1);
}
closedir(dir);
}
notifications_hook(notifdir);
ifd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if(ifd < 0)
return 1;
if(inotify_add_watch(ifd, notifdir,
IN_CLOSE_WRITE | IN_MOVED_TO | IN_DELETE) < 0) {
close(ifd);
return 1;
}
pfd.fd = ifd;
pfd.events = POLLIN;
while(!stop_requested) {
char buf[4096];
ssize_t n;
int off = 0;
int rc = poll(&pfd, 1, -1);
if(rc < 0) {
if(errno == EINTR)
continue;
break;
}
n = read(ifd, buf, sizeof(buf));
if(n <= 0)
continue;
while(off < n) {
const struct inotify_event *ev =
(const struct inotify_event *)(buf + off);
if(ev->len > 0 && ev->name[0] != '.' &&
(ev->mask & (IN_CLOSE_WRITE | IN_MOVED_TO))) {
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s/%s", notifdir, ev->name);
handle_new_notif_file(notifdir, path, 0);
}
off += (int)(sizeof(*ev) + ev->len);
}
notifications_hook(notifdir);
}
close(ifd);
return 0;
}
@@ -0,0 +1,110 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Wall-clock aligned periodic runner replacing sxmo_run_aligned.sh + sxmo_aligned_sleep. */
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
static volatile sig_atomic_t stop_requested = 0;
static volatile pid_t active_child = -1;
static void handle_stop(int sig)
{
pid_t child = active_child;
(void)sig;
stop_requested = 1;
if(child > 0)
kill(child, SIGTERM);
}
static void aligned_sleep(long interval)
{
struct timespec now;
struct timespec req;
long long rem_ns;
long long rem_s;
if(clock_gettime(CLOCK_REALTIME, &now) < 0) {
req.tv_sec = (time_t)interval;
req.tv_nsec = 0;
} else {
rem_ns = 1000000000LL - (long long)now.tv_nsec;
rem_s = (interval - 1LL) - ((long long)now.tv_sec % interval);
if(rem_s < 0)
rem_s += interval;
if(rem_ns >= 1000000000LL) {
rem_ns -= 1000000000LL;
rem_s += 1LL;
}
req.tv_sec = (time_t)rem_s;
req.tv_nsec = (long)rem_ns;
}
while(!stop_requested) {
if(nanosleep(&req, &req) == 0)
break;
if(errno != EINTR)
break;
}
}
int main(int argc, char **argv)
{
struct sigaction sa;
char *endptr = NULL;
long interval;
if(argc < 3) {
fprintf(stderr, "Usage: %s <interval_sec> <cmd> [args...]\n", argv[0]);
return 1;
}
interval = strtol(argv[1], &endptr, 10);
if(!endptr || *endptr != '\0' || interval <= 0) {
fprintf(stderr, "%s: invalid interval '%s'\n", argv[0], argv[1]);
return 1;
}
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_stop;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
while(!stop_requested) {
pid_t pid = fork();
if(pid == 0) {
sigset_t empty;
sigemptyset(&empty);
sigprocmask(SIG_SETMASK, &empty, NULL);
sa.sa_handler = SIG_DFL;
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
execvp(argv[2], &argv[2]);
_exit(127);
}
if(pid > 0) {
int status;
active_child = pid;
while(waitpid(pid, &status, 0) < 0) {
if(errno != EINTR)
break;
}
active_child = -1;
}
if(stop_requested)
break;
aligned_sleep(interval);
}
return 0;
}
@@ -0,0 +1,281 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Compiled X11 session supervisor loop replacing bananarchy-x11-session.sh tail. */
#include <ctype.h>
#include <dirent.h>
#include <limits.h>
#include <time.h>
#include "common.h"
static volatile sig_atomic_t stop_requested = 0;
static volatile pid_t dwm_pid = -1;
static void handle_signal(int sig)
{
pid_t child = dwm_pid;
(void)sig;
stop_requested = 1;
if(child > 0)
kill(child, SIGTERM);
}
static void spawn_detached(char *const argv[])
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static int run_sync_quiet(char *const argv[])
{
pid_t pid = fork();
int st = 0;
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
if(pid < 0)
return -1;
while(waitpid(pid, &st, 0) < 0) {
if(errno != EINTR)
return -1;
}
return WIFEXITED(st) ? WEXITSTATUS(st) : -1;
}
static int proc_is_running(const char *target)
{
DIR *dir = opendir("/proc");
struct dirent *de;
size_t tlen = strlen(target);
if(!dir)
return 0;
while((de = readdir(dir)) != NULL) {
char comm_path[300];
char buf[64];
int n;
FILE *f;
if(!isdigit((unsigned char)de->d_name[0]))
continue;
snprintf(comm_path, sizeof(comm_path), "/proc/%s/comm", de->d_name);
f = fopen(comm_path, "r");
if(!f)
continue;
if(!fgets(buf, sizeof(buf), f))
buf[0] = '\0';
fclose(f);
n = (int)strlen(buf);
while(n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r'))
buf[--n] = '\0';
if((size_t)n == tlen && strcmp(buf, target) == 0) {
closedir(dir);
return 1;
}
}
closedir(dir);
return 0;
}
static int session_pid_matches(const char *pid_file)
{
char buf[64];
long val;
if(read_first_line(pid_file, buf, sizeof(buf)) < 0 || buf[0] == '\0')
return 0;
val = strtol(buf, NULL, 10);
return val == (long)getpid();
}
static int screen_is_dark(void)
{
char buf[32];
if(read_first_line("/sys/class/backlight/backlight/brightness",
buf, sizeof(buf)) == 0 &&
strcmp(buf, "0") == 0) {
return 1;
}
return 0;
}
static void resolve_wallpaper(char *wp_file, size_t wp_len,
char *wp_flag, size_t flag_len)
{
const char *xdg_cfg = getenv("XDG_CONFIG_HOME");
const char *home = getenv("HOME");
char cfg_base[PATH_MAX];
char path_buf[PATH_MAX + 64];
char line[PATH_MAX];
safe_copy(wp_file, wp_len, "/usr/share/wallpapers/bananarchy.png");
safe_copy(wp_flag, flag_len, "--bg-fill");
if(xdg_cfg && *xdg_cfg) {
safe_copy(cfg_base, sizeof(cfg_base), xdg_cfg);
} else {
snprintf(cfg_base, sizeof(cfg_base), "%s/.config",
(home && *home) ? home : "/home/user");
}
snprintf(path_buf, sizeof(path_buf), "%s/sxmo/wallpaper", cfg_base);
if(read_first_line(path_buf, line, sizeof(line)) == 0 && line[0] != '\0') {
if(access(line, F_OK) == 0)
safe_copy(wp_file, wp_len, line);
}
snprintf(path_buf, sizeof(path_buf), "%s/sxmo/wallpaper_mode", cfg_base);
if(read_first_line(path_buf, line, sizeof(line)) == 0) {
if(strcmp(line, "scale") == 0 || strcmp(line, "--bg-scale") == 0)
safe_copy(wp_flag, flag_len, "--bg-scale");
else if(strcmp(line, "max") == 0 || strcmp(line, "--bg-max") == 0)
safe_copy(wp_flag, flag_len, "--bg-max");
else if(strcmp(line, "center") == 0 || strcmp(line, "--bg-center") == 0)
safe_copy(wp_flag, flag_len, "--bg-center");
else if(strcmp(line, "tile") == 0 || strcmp(line, "--bg-tile") == 0)
safe_copy(wp_flag, flag_len, "--bg-tile");
}
}
int main(int argc, char **argv)
{
const char *xdg_rt = getenv("XDG_RUNTIME_DIR");
const char *home = getenv("HOME");
char default_pid_file[PATH_MAX];
const char *pid_file;
struct sigaction sa;
int first_iter = 1;
if(argc >= 2 && argv[1][0] != '\0') {
pid_file = argv[1];
} else {
snprintf(default_pid_file, sizeof(default_pid_file),
"%s/bananarchy-x11-session.pid",
(xdg_rt && *xdg_rt) ? xdg_rt : "/run/user/10000");
pid_file = default_pid_file;
}
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
while(!stop_requested && session_pid_matches(pid_file)) {
char wp_file[PATH_MAX];
char wp_flag[32];
int dark;
pid_t child;
if(proc_is_running("dwm"))
return 0;
dark = screen_is_dark();
if(!dark) {
char xres[PATH_MAX];
snprintf(xres, sizeof(xres), "%s/.Xresources",
(home && *home) ? home : "/home/user");
char *const xrdb_argv[] = {
(char *)"xrdb", (char *)"-merge", xres, NULL
};
char *const dunst_argv[] = {
(char *)"/usr/bin/bananarchy-sync-dunst-theme",
(char *)"--no-restart", NULL
};
run_sync_quiet(xrdb_argv);
run_sync_quiet(dunst_argv);
}
resolve_wallpaper(wp_file, sizeof(wp_file), wp_flag, sizeof(wp_flag));
if(!dark) {
char *const feh_argv[] = {
(char *)"feh", (char *)"--no-fehbg", wp_flag, wp_file, NULL
};
spawn_detached(feh_argv);
}
if(!first_iter && !proc_is_running("fcitx5")) {
char *const super_argv[] = {
(char *)"superctl", (char *)"start", (char *)"fcitx5", NULL
};
if(run_sync_quiet(super_argv) != 0) {
char *const fcitx_argv[] = {
(char *)"/usr/bin/bananarchy-fcitx5.sh", NULL
};
spawn_detached(fcitx_argv);
}
}
first_iter = 0;
child = fork();
if(child == 0) {
int fd;
if(access("/tmp/bananarchy_ext_logging", F_OK) == 0) {
fd = open("/tmp/dwm.log", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
} else {
fd = open("/dev/null", O_WRONLY | O_CLOEXEC);
}
if(fd >= 0) {
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if(fd > STDERR_FILENO)
close(fd);
}
execlp("dwm", "dwm", (char *)NULL);
_exit(127);
}
if(child > 0) {
int st;
pid_t w;
dwm_pid = child;
for(;;) {
w = waitpid(-1, &st, 0);
if(w == child)
break;
if(w < 0 && errno != EINTR)
break;
}
dwm_pid = -1;
}
if(stop_requested || !session_pid_matches(pid_file) || proc_is_running("dwm"))
return 0;
{
struct timespec req = { 0, 200000000L };
nanosleep(&req, NULL);
}
}
return 0;
}
@@ -0,0 +1,575 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
/* Compiled audio jack + PipeWire monitor replacing sxmo_soundmonitor.sh + evtest. */
#include <ctype.h>
#include <limits.h>
#include <poll.h>
#include "common.h"
static volatile sig_atomic_t stop_requested = 0;
static volatile pid_t pactl_pid = -1;
static void handle_signal(int sig)
{
pid_t child = pactl_pid;
(void)sig;
stop_requested = 1;
if(child > 0)
kill(child, SIGTERM);
}
static void spawn_detached(char *const argv[])
{
pid_t mid = fork();
if(mid == 0) {
pid_t leaf;
setsid();
leaf = fork();
if(leaf == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
_exit(0);
}
if(mid > 0) {
int st;
while(waitpid(mid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static void run_sync_quiet(char *const argv[])
{
pid_t pid = fork();
int st = 0;
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
if(pid > 0) {
while(waitpid(pid, &st, 0) < 0 && errno == EINTR) {
}
}
}
static int run_capture(char *const argv[], char *out, size_t out_len)
{
int pfd[2];
pid_t pid;
size_t total = 0;
int st = 0;
if(!out || out_len == 0)
return -1;
out[0] = '\0';
if(pipe2(pfd, O_CLOEXEC) < 0)
return -1;
pid = fork();
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
if(pfd[1] > STDERR_FILENO)
close(pfd[1]);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
close(pfd[1]);
if(pid < 0) {
close(pfd[0]);
return -1;
}
while(total < out_len - 1) {
ssize_t n = read(pfd[0], out + total, out_len - 1 - total);
if(n > 0) {
total += (size_t)n;
continue;
}
if(n < 0 && errno == EINTR)
continue;
break;
}
out[total] = '\0';
close(pfd[0]);
while(waitpid(pid, &st, 0) < 0 && errno == EINTR) {
}
return WIFEXITED(st) ? WEXITSTATUS(st) : -1;
}
static int str_contains_ci(const char *haystack, const char *needle)
{
size_t nlen = strlen(needle);
size_t i;
if(nlen == 0)
return 1;
for(i = 0; haystack[i]; i++) {
size_t j = 0;
while(j < nlen && haystack[i + j] &&
tolower((unsigned char)haystack[i + j]) ==
tolower((unsigned char)needle[j])) {
j++;
}
if(j == nlen)
return 1;
}
return 0;
}
static int open_jack_dev(char *dev_path, size_t dev_len)
{
glob_t gl;
size_t i;
int fd = -1;
dev_path[0] = '\0';
if(glob("/sys/class/input/event*/device/name", 0, NULL, &gl) != 0)
return -1;
for(i = 0; i < gl.gl_pathc; i++) {
char name[128];
const char *ev;
char *slash;
char ev_name[32];
if(read_first_line(gl.gl_pathv[i], name, sizeof(name)) < 0)
continue;
if(!str_contains_ci(name, "jack") && !str_contains_ci(name, "headset"))
continue;
ev = strstr(gl.gl_pathv[i], "event");
if(!ev)
continue;
slash = strchr(ev, '/');
if(!slash || (size_t)(slash - ev) >= sizeof(ev_name))
continue;
memcpy(ev_name, ev, (size_t)(slash - ev));
ev_name[slash - ev] = '\0';
snprintf(dev_path, dev_len, "/dev/input/%s", ev_name);
fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if(fd >= 0)
break;
}
globfree(&gl);
return fd;
}
static int query_ev_sw(int fd, unsigned int code, const char *amixer_name)
{
if(fd >= 0) {
unsigned char sw[(SW_MAX + 7) / 8 + 1];
memset(sw, 0, sizeof(sw));
if(ioctl(fd, BA_EVIOCGSW(sizeof(sw)), sw) >= 0)
return (sw[code / 8] & (1u << (code % 8))) != 0;
}
{
char out[256];
char *const argv[] = {
(char *)"amixer", (char *)"-c", (char *)"0",
(char *)"cget", (char *)amixer_name, NULL
};
if(run_capture(argv, out, sizeof(out)) == 0 &&
strstr(out, ": values=on") != NULL) {
return 1;
}
}
return 0;
}
static void find_bt_sink(char *out, size_t out_len)
{
char raw[2048];
char *line;
char *save = NULL;
char *const argv[] = {
(char *)"pactl", (char *)"list", (char *)"short", (char *)"sinks", NULL
};
out[0] = '\0';
if(run_capture(argv, raw, sizeof(raw)) != 0)
return;
for(line = strtok_r(raw, "\n", &save); line; line = strtok_r(NULL, "\n", &save)) {
char *c1 = strtok(line, " \t");
char *c2 = c1 ? strtok(NULL, " \t") : NULL;
if(c2 && strncmp(c2, "bluez_output.", 13) == 0) {
safe_copy(out, out_len, c2);
return;
}
}
}
static void sxmo_audio_cmd(const char *arg1, const char *arg2)
{
if(arg2) {
char *const argv[] = {
(char *)"sxmo_audio.sh", (char *)"device",
(char *)arg1, (char *)arg2, NULL
};
run_sync_quiet(argv);
} else {
char *const argv[] = {
(char *)"sxmo_audio.sh", (char *)"device", (char *)arg1, NULL
};
run_sync_quiet(argv);
}
}
static void write_state_file(const char *path, const char *val)
{
FILE *f = fopen(path, "w");
if(!f)
return;
fputs(val, f);
fputc('\n', f);
fclose(f);
}
static void handle_jack_insert(int jack_fd)
{
char cur_out[64] = "";
char *const get_argv[] = {
(char *)"sxmo_audio.sh", (char *)"device", (char *)"get", NULL
};
if(run_capture(get_argv, cur_out, sizeof(cur_out)) != 0 || cur_out[0] == '\0') {
safe_copy(cur_out, sizeof(cur_out), "Speaker");
} else {
cur_out[strcspn(cur_out, "\r\n")] = '\0';
}
if(strcmp(cur_out, "Headphones") != 0)
write_state_file("/tmp/sxmo_prev_out_device", cur_out);
write_state_file("/tmp/sxmo_jack_plugged", "1");
if(query_ev_sw(jack_fd, SW_MICROPHONE_INSERT, "name='Mic Jack'")) {
write_state_file("/tmp/sxmo_audio_in_device", "Headset");
sxmo_audio_cmd("setinput", "Headset");
} else {
write_state_file("/tmp/sxmo_audio_in_device", "Mic1");
}
sxmo_audio_cmd("set", "Headphones");
}
static void handle_jack_remove(void)
{
char incall[16] = "";
const char *target = "Speaker";
write_state_file("/tmp/sxmo_jack_plugged", "0");
write_state_file("/tmp/sxmo_audio_in_device", "Mic1");
sxmo_audio_cmd("setinput", "Mic1");
if(read_first_line("/tmp/sxmo_in_call", incall, sizeof(incall)) == 0 &&
strcmp(incall, "1") == 0) {
target = "Earpiece";
}
sxmo_audio_cmd("set", target);
}
static void handle_jack_events(int *jack_fd_ptr)
{
int fd = *jack_fd_ptr;
struct input_event ev;
ssize_t n;
while((n = read(fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) {
if(ev.type != EV_SW)
continue;
if(ev.code == SW_HEADPHONE_INSERT && ev.value == 1) {
struct timespec ts = { 0, 100000000L };
nanosleep(&ts, NULL);
handle_jack_insert(fd);
} else if(ev.code == SW_HEADPHONE_INSERT && ev.value == 0) {
handle_jack_remove();
} else if(ev.code == SW_MICROPHONE_INSERT && ev.value == 1) {
sxmo_audio_cmd("setinput", "Headset");
} else if(ev.code == SW_MICROPHONE_INSERT && ev.value == 0) {
sxmo_audio_cmd("setinput", "Mic1");
}
}
if(n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
close(fd);
*jack_fd_ptr = -1;
}
}
static int start_pactl_subscribe(char *prev_bt, size_t prev_bt_len)
{
int pfd[2];
pid_t pid;
char cur_out[64] = "";
find_bt_sink(prev_bt, prev_bt_len);
if(prev_bt[0] != '\0') {
read_first_line("/tmp/sxmo_audio_out_device", cur_out, sizeof(cur_out));
if(strcmp(cur_out, "Bluetooth") != 0)
sxmo_audio_cmd("set", "Bluetooth");
else
sxmo_audio_cmd("apply", NULL);
}
if(pipe2(pfd, O_NONBLOCK | O_CLOEXEC) < 0)
return -1;
pid = fork();
if(pid == 0) {
int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
close(pfd[0]);
dup2(pfd[1], STDOUT_FILENO);
if(pfd[1] > STDERR_FILENO)
close(pfd[1]);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execlp("pactl", "pactl", "subscribe", (char *)NULL);
_exit(127);
}
close(pfd[1]);
if(pid < 0) {
close(pfd[0]);
return -1;
}
pactl_pid = pid;
return pfd[0];
}
static void dispatch_pactl_line(const char *line, char *prev_bt, size_t prev_bt_len)
{
if((strstr(line, "Event 'new' on sink") != NULL) ||
(strstr(line, "Event 'new' on card") != NULL) ||
(strstr(line, "Event 'change' on card") != NULL)) {
char bt_sink[128] = "";
find_bt_sink(bt_sink, sizeof(bt_sink));
if(bt_sink[0] != '\0' && strcmp(bt_sink, prev_bt) != 0) {
safe_copy(prev_bt, prev_bt_len, bt_sink);
sxmo_audio_cmd("set", "Bluetooth");
}
{
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"volume", NULL
};
spawn_detached(sb_argv);
}
} else if((strstr(line, "Event 'remove' on sink") != NULL) ||
(strstr(line, "Event 'remove' on card") != NULL)) {
char bt_sink[128] = "";
find_bt_sink(bt_sink, sizeof(bt_sink));
if(bt_sink[0] == '\0' && prev_bt[0] != '\0') {
char cur_out[64] = "";
prev_bt[0] = '\0';
read_first_line("/tmp/sxmo_audio_out_device", cur_out, sizeof(cur_out));
if(strcmp(cur_out, "Bluetooth") == 0) {
char jbuf[16] = "";
if(read_first_line("/tmp/sxmo_jack_plugged", jbuf, sizeof(jbuf)) == 0 &&
strcmp(jbuf, "1") == 0) {
sxmo_audio_cmd("set", "Headphones");
} else if(access("/tmp/sxmo_in_call", R_OK) == 0) {
sxmo_audio_cmd("set", "Earpiece");
} else {
sxmo_audio_cmd("set", "Speaker");
}
}
}
{
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"volume", NULL
};
spawn_detached(sb_argv);
}
} else if((strstr(line, "Event 'change' on sink") != NULL) ||
(strstr(line, "Event 'change' on source") != NULL)) {
if(access("/tmp/sxmo_volset.lock", F_OK) != 0) {
char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"volume", NULL
};
spawn_detached(sb_argv);
}
}
}
int main(void)
{
struct sigaction sa;
int inotify_fd;
int jack_fd;
char jack_path[64] = "";
int pactl_fd;
char prev_bt[128] = "";
char pactl_buf[4096];
size_t pactl_len = 0;
long long pactl_retry_at = -1;
long long jack_retry_at = -1;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
inotify_fd = open_input_inotify();
jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT, "name='Headphone Jack'")) {
handle_jack_insert(jack_fd);
} else {
char bt_sink[128] = "";
write_state_file("/tmp/sxmo_jack_plugged", "0");
find_bt_sink(bt_sink, sizeof(bt_sink));
if(bt_sink[0] != '\0')
sxmo_audio_cmd("set", "Bluetooth");
else
sxmo_audio_cmd("apply", NULL);
}
if(jack_fd < 0)
jack_retry_at = now_ms() + 5000;
pactl_fd = start_pactl_subscribe(prev_bt, sizeof(prev_bt));
if(pactl_fd < 0)
pactl_retry_at = now_ms() + 10000;
while(!stop_requested) {
struct pollfd fds[3];
int nfds = 0;
int idx_inot = -1;
int idx_jack = -1;
int idx_pactl = -1;
int timeout_ms = -1;
long long now = now_ms();
if(inotify_fd >= 0) {
idx_inot = nfds;
fds[nfds].fd = inotify_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(jack_fd >= 0) {
idx_jack = nfds;
fds[nfds].fd = jack_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(pactl_fd >= 0) {
idx_pactl = nfds;
fds[nfds].fd = pactl_fd;
fds[nfds].events = POLLIN;
fds[nfds].revents = 0;
nfds++;
}
if(pactl_retry_at > 0) {
int rem = (pactl_retry_at > now) ? (int)(pactl_retry_at - now) : 0;
if(timeout_ms < 0 || rem < timeout_ms)
timeout_ms = rem;
}
if(jack_retry_at > 0 && jack_fd < 0) {
int rem = (jack_retry_at > now) ? (int)(jack_retry_at - now) : 0;
if(timeout_ms < 0 || rem < timeout_ms)
timeout_ms = rem;
}
if(nfds == 0) {
struct timespec ts = { 1, 0 };
nanosleep(&ts, NULL);
} else if(poll(fds, (nfds_t)nfds, timeout_ms) < 0) {
if(errno == EINTR)
continue;
break;
}
if(stop_requested)
break;
if(idx_inot >= 0 && (fds[idx_inot].revents & POLLIN) &&
drain_inotify(inotify_fd) && jack_fd < 0) {
jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
if(jack_fd >= 0) {
jack_retry_at = -1;
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT, "name='Headphone Jack'"))
handle_jack_insert(jack_fd);
}
}
if(idx_jack >= 0 && (fds[idx_jack].revents & (POLLIN | POLLERR | POLLHUP))) {
handle_jack_events(&jack_fd);
if(jack_fd < 0)
jack_retry_at = now_ms() + 5000;
}
if(idx_pactl >= 0 && (fds[idx_pactl].revents & (POLLIN | POLLERR | POLLHUP))) {
int eof = 0;
for(;;) {
ssize_t n;
if(pactl_len >= sizeof(pactl_buf) - 1)
pactl_len = 0;
n = read(pactl_fd, pactl_buf + pactl_len,
sizeof(pactl_buf) - 1 - pactl_len);
if(n > 0) {
char *nl;
pactl_len += (size_t)n;
pactl_buf[pactl_len] = '\0';
while((nl = strchr(pactl_buf, '\n')) != NULL) {
size_t rest;
*nl = '\0';
dispatch_pactl_line(pactl_buf, prev_bt, sizeof(prev_bt));
rest = (size_t)(pactl_buf + pactl_len - (nl + 1));
memmove(pactl_buf, nl + 1, rest);
pactl_len = rest;
pactl_buf[pactl_len] = '\0';
}
continue;
}
if(n == 0 || (errno != EAGAIN && errno != EWOULDBLOCK))
eof = 1;
break;
}
if(eof) {
close(pactl_fd);
pactl_fd = -1;
if(pactl_pid > 0) {
int st;
waitpid(pactl_pid, &st, WNOHANG);
pactl_pid = -1;
}
pactl_retry_at = now_ms() + 10000;
}
}
now = now_ms();
if(jack_fd < 0 && jack_retry_at > 0 && now >= jack_retry_at) {
jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
jack_retry_at = (jack_fd < 0) ? (now + 5000) : -1;
}
if(pactl_fd < 0 && pactl_retry_at > 0 && now >= pactl_retry_at) {
pactl_fd = start_pactl_subscribe(prev_bt, sizeof(prev_bt));
pactl_retry_at = (pactl_fd < 0) ? (now + 10000) : -1;
}
}
if(pactl_pid > 0) {
int st;
kill(pactl_pid, SIGTERM);
waitpid(pactl_pid, &st, 0);
}
if(pactl_fd >= 0)
close(pactl_fd);
if(jack_fd >= 0)
close(jack_fd);
if(inotify_fd >= 0)
close(inotify_fd);
return 0;
}
+45
View File
@@ -32,7 +32,10 @@
#define EV_SW 0x05 #define EV_SW 0x05
#define KEY_MAX 0x2ff #define KEY_MAX 0x2ff
#define SW_LID 0x00 #define SW_LID 0x00
#define SW_HEADPHONE_INSERT 0x02
#define SW_MICROPHONE_INSERT 0x04
#define SW_KEYPAD_SLIDE 0x0a #define SW_KEYPAD_SLIDE 0x0a
#define SW_MAX 0x0f
#define KEY_VOLUMEDOWN 114 #define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115 #define KEY_VOLUMEUP 115
#ifndef KEY_POWER #ifndef KEY_POWER
@@ -46,6 +49,8 @@
((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16)) ((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16))
#define BA_EVIOCGBIT(ev, len) \ #define BA_EVIOCGBIT(ev, len) \
BA_IOC(2U, 'E', 0x20U + (unsigned int)(ev), (unsigned int)(len)) BA_IOC(2U, 'E', 0x20U + (unsigned int)(ev), (unsigned int)(len))
#define BA_EVIOCGSW(len) \
BA_IOC(2U, 'E', 0x1bU, (unsigned int)(len))
/* Match the kernel evdev record layout (__kernel_ulong_t sec/usec), not musl /* Match the kernel evdev record layout (__kernel_ulong_t sec/usec), not musl
* time64 struct timeval: on 32-bit armv7 musl, struct timeval is 16 bytes * time64 struct timeval: on 32-bit armv7 musl, struct timeval is 16 bytes
@@ -304,4 +309,44 @@ static BA_UNUSED long long now_ms(void)
return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL; return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL;
} }
static BA_UNUSED int read_first_line(const char *path, char *buf, size_t len)
{
FILE *f;
size_t n;
if(!buf || len == 0)
return -1;
buf[0] = '\0';
f = fopen(path, "r");
if(!f)
return -1;
if(!fgets(buf, (int)len, f)) {
fclose(f);
buf[0] = '\0';
return -1;
}
fclose(f);
n = strlen(buf);
while(n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r'))
buf[--n] = '\0';
return 0;
}
static BA_UNUSED pid_t spawn_async_cmd(char *const argv[])
{
pid_t pid = fork();
int nullfd;
if(pid != 0)
return pid;
nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
if(nullfd >= 0) {
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
if(nullfd > STDERR_FILENO)
close(nullfd);
}
execvp(argv[0], argv);
_exit(127);
}
#endif #endif