feat(cellular): add datapath validation and reject unimplemented BAM transport
Offline project checks / check (push) Canceled after 0s
Offline project checks / check (push) Canceled after 0s
This commit is contained in:
@@ -101,27 +101,52 @@ def parse_mmcli_modem_info(raw_text):
|
||||
return info
|
||||
|
||||
|
||||
def cellular_datapath_status(sys_path='/sys'):
|
||||
"""Inspect transport backing; a driver binding or interface name is insufficient.
|
||||
|
||||
The current IPA v2.6 shim has no BAM TX/RX implementation. Reject it even
|
||||
when it exposes rmnet_ipa0. A future real backend must explicitly expose
|
||||
modem/datapath_ready=1 before this integration permits activation.
|
||||
"""
|
||||
root = Path(sys_path)
|
||||
rows = []
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
return path.read_text().strip()
|
||||
except OSError:
|
||||
return ''
|
||||
|
||||
def transport(iface, seen):
|
||||
resolved = iface.resolve()
|
||||
if resolved in seen:
|
||||
return False, 'cyclic lower-interface relationship'
|
||||
seen = seen | {resolved}
|
||||
for lower in sorted(iface.glob('lower_*')):
|
||||
ready, reason = transport(lower, seen)
|
||||
if ready:
|
||||
return ready, reason
|
||||
device = iface / 'device'
|
||||
if not (device / 'driver').exists():
|
||||
return False, 'no bound hardware transport'
|
||||
version = read(device / 'ipa_version')
|
||||
compatible = read(device / 'of_node/compatible').split('\0')
|
||||
legacy = (version.startswith('2.') or
|
||||
any(value in ('qcom,sdm660-ipa', 'qcom,ipa-v2.6') for value in compatible))
|
||||
if legacy and read(device / 'modem/datapath_ready') != '1':
|
||||
return False, 'IPA v2.6 shim: BAM TX/RX not implemented'
|
||||
return True, 'bound hardware transport (IP connectivity unverified)'
|
||||
|
||||
for iface in sorted((root / 'class/net').glob('*')):
|
||||
if iface.name.startswith(('rmnet', 'ipa', 'wwan')):
|
||||
ready, reason = transport(iface, set())
|
||||
rows.append({'interface': iface.name, 'ready': ready, 'reason': reason})
|
||||
return {'ready': any(row['ready'] for row in rows), 'interfaces': rows}
|
||||
|
||||
|
||||
def has_cellular_datapath(sys_path='/sys'):
|
||||
"""Check if kernel has an active hardware cellular data path (bound IPA device or rmnet/wwan network interface)."""
|
||||
p = Path(sys_path)
|
||||
net_dir = p / 'class/net'
|
||||
if net_dir.is_dir():
|
||||
try:
|
||||
for iface in net_dir.iterdir():
|
||||
if iface.name.startswith(('rmnet', 'ipa', 'wwan0')):
|
||||
return True
|
||||
except OSError:
|
||||
pass
|
||||
ipa_driver = p / 'bus/platform/drivers/ipa'
|
||||
if ipa_driver.is_dir():
|
||||
try:
|
||||
ignored = {'bind', 'unbind', 'uevent', 'module'}
|
||||
for item in ipa_driver.iterdir():
|
||||
if item.name not in ignored:
|
||||
return True
|
||||
except OSError:
|
||||
pass
|
||||
return False
|
||||
"""Return whether a hardware transport is available for NM activation."""
|
||||
return cellular_datapath_status(sys_path)['ready']
|
||||
|
||||
|
||||
def check_battery_gate(min_capacity=15, min_voltage_uv=3700000, sys_path='/sys'):
|
||||
@@ -359,7 +384,7 @@ def configure_cellular(apn=None, ifname='*', executor=subprocess.run):
|
||||
def toggle_cellular(activate=True, executor=subprocess.run, datapath_checker=has_cellular_datapath):
|
||||
"""Activate or deactivate cellular data connection."""
|
||||
if activate and not datapath_checker():
|
||||
raise RuntimeError("No hardware IPA or rmnet cellular data path in kernel; activation skipped to protect modem stability.")
|
||||
raise RuntimeError("No usable cellular hardware transport; an IPA v2.6 shim or interface name alone cannot carry data.")
|
||||
action = 'up' if activate else 'down'
|
||||
cmd = ['nmcli', 'connection', action, CONNECTION_NAME]
|
||||
return executor(cmd, check=True)
|
||||
@@ -586,8 +611,10 @@ def main():
|
||||
|
||||
if args.status:
|
||||
result = query_modem_info()
|
||||
datapath = cellular_datapath_status()
|
||||
if args.json:
|
||||
result['has_datapath'] = has_cellular_datapath()
|
||||
result['has_datapath'] = datapath['ready']
|
||||
result['datapath'] = datapath
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
if result.get('status') == 'ok':
|
||||
@@ -606,8 +633,10 @@ def main():
|
||||
print(f"Signal Quality: {modem.get('signal_percent')}%")
|
||||
if modem.get('access_tech'):
|
||||
print(f"Access Tech: {modem.get('access_tech')}")
|
||||
if not has_cellular_datapath():
|
||||
print("Data Path: Disabled (IPA hardware datapath not present in kernel)")
|
||||
if not datapath['ready']:
|
||||
print("Data Path: Unavailable (no usable hardware transport)")
|
||||
for row in datapath['interfaces']:
|
||||
print(f" {row['interface']}: {row['reason']}")
|
||||
else:
|
||||
print(f"Cellular Status: {result.get('message')}")
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user