"""OMEGA AB-009: offline driver adaptation evidence. No build or device changes.""" import argparse, csv, hashlib, re from datetime import datetime from pathlib import Path RULES = { 'dispatch_and_assembly': r'\biwl_mvm_(?:rx_csi_header|rx_csi_chunk|csi_complete|csi_steal|csi_free_pages)\b|CSI_(?:HEADER|CHUNKS)_NOTIFICATION', 'activation_and_firmware': r'\biwl_mvm_send_csi_cmd\b|\biwl_dbgfs_csi_\w+|CSI_REPORTING|\b\w*CSI\w*(?:CMD|CONFIG)\w*\b', 'vendor_abi': r'\biwl_mvm_(?:vendor_csi_register|send_csi_event)\b|IWL_MVM_VENDOR_\w*CSI\w*|cfg80211_vendor_event_alloc(?:_ucast)?\b', 'state_and_buffers': r'\b(?:iwl_csi_data_buffer|csi_data_entries|IWL_CSI_MAX_EXPECTED_CHUNKS|rxb_steal_page|rxb_addr)\b', 'build_dependencies': r'\b(?:CONFIG_)?(?:IWLMVM_VENDOR_CMDS|IWLWIFI_DEBUGFS|MAC80211_DEBUGFS|IWLMEI)\b|vendor-cmd\.o|debugfs\.o', 'interface_requirements': r'\b(?:NL80211_IFTYPE_MONITOR|WIPHY_VENDOR_CMD_NEED_\w+|NL80211_IFTYPE_STATION)\b|\b(?:vif|wdev)->iftype\b', } RULES = {k: re.compile(v,re.I) for k,v in RULES.items()} SYMBOLS = ['iwl_mvm_send_csi_cmd','iwl_dbgfs_csi_enabled_write','iwl_mvm_rx_csi_header','iwl_mvm_rx_csi_chunk','iwl_mvm_csi_complete','iwl_mvm_vendor_csi_register','iwl_mvm_send_csi_event','cfg80211_vendor_event_alloc_ucast','rxb_steal_page','IWL_MVM_VENDOR_CMD_CSI_EVENT','IWL_MVM_VENDOR_ATTR_CSI_HDR','IWL_MVM_VENDOR_ATTR_CSI_DATA','IWL_UCODE_TLV_CAPA_CSI_REPORTING','IWL_UCODE_TLV_CAPA_CSI_REPORTING_V2'] # Entire bounded regions from the observed Core46 commit; line numbers are # anchors from AB-007/008, not assumptions about other revisions. REGIONS={'mvm/debugfs.c':[(1970,2225),(2260,2295),(2480,2540)],'mvm/vendor-cmd.c':[(1515,1555),(1735,1785),(1835,2025)],'mvm/ops.c':[(250,295),(890,930)],'mvm/mvm.h':[(1250,1310),(2330,2370)],'fw/file.h':[(415,440),(490,510)],'Kconfig.noupstream':[(75,110)]} def main(): p=argparse.ArgumentParser(description=__doc__); p.add_argument('--root',type=Path,default=Path.home()/'Documents'/'OMEGA'/'OMICRON'); p.add_argument('--run',default='AB-007-20261127-162346-512367'); a=p.parse_args() root=a.root.resolve(); run=root/'Analysis'/a.run if not (root/'Index'/'Current-Checkpoint.txt').is_file(): raise SystemExit('OMEGA root not found') with (run/'retrieval.csv').open(encoding='utf-8-sig',newline='') as f: rows=list(csv.DictReader(f)) files=[]; missing=[] for r in rows: if r['status']!='OK': missing.append(f"{r['source']} {r['file']}: {r['status']}"); continue path=run/'sources'/r['source']/r['file']; data=path.read_bytes() if hashlib.sha256(data).hexdigest().lower()!=r['sha256'].lower(): raise SystemExit(f'Hash mismatch: {path}') files.append((r,data.decode('utf-8').splitlines())) if not files: raise SystemExit('No verified source files') out=root/'Analysis'/('AB-009-'+datetime.now().strftime('%Y%m%d-%H%M%S-%f')); out.mkdir() hits=[]; contexts=[]; symbols={s:[] for s in SYMBOLS} for r,lines in files: # Retain the lexical preprocessor stack; this is not preprocessing. guards=[]; selected={} for i,line in enumerate(lines): m=re.match(r'\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b(.*)',line) if m: op,rest=m.groups(); desc=f'{i+1}: #{op}{rest}' if op in ('if','ifdef','ifndef'): guards.append(desc) elif op in ('elif','else') and guards: guards[-1]+=' -> '+desc elif op=='endif' and guards: guards.pop() tags=[k for k,v in RULES.items() if v.search(line)] if tags: selected[i]=tags; hits.append(dict(source=r['source'],file=r['file'],line=i+1,topics=';'.join(tags),guards=' | '.join(guards),text=line.strip(),url=r['url'],sha256=r['sha256'])) for s in SYMBOLS: if re.search(r'\b'+re.escape(s)+r'\b',line): symbols[s].append((r['source'],r['file'],i+1,line.strip())) windows=[(max(0,i-12),min(len(lines),i+16)) for i in selected] if r['source']=='intel-core46': windows.extend((lo-1,min(hi,len(lines))) for lo,hi in REGIONS.get(r['file'],[]) if lo<=len(lines)) if Path(r['file']).name.startswith(('Kconfig','Makefile')): windows.append((0,len(lines))) merged=[] for lo,hi in sorted(windows): if merged and lo<=merged[-1][1]: merged[-1][1]=max(hi,merged[-1][1]) else: merged.append([lo,hi]) if merged: contexts.append(f"\n=== {r['source']} / {r['file']} ===\n{r['url']}\nSHA256 {r['sha256']}") for lo,hi in merged: contexts.append(f'--- lines {lo+1}-{hi} ---'); contexts.extend(f'{i+1:5} {lines[i]}' for i in range(lo,hi)) with (out/'evidence.csv').open('w',encoding='utf-8-sig',newline='') as f: w=csv.DictWriter(f,fieldnames=['source','file','line','topics','guards','text','url','sha256']); w.writeheader(); w.writerows(hits) (out/'AB-009-Source-Context.txt').write_text('\n'.join(contexts)+'\n',encoding='utf-8') report=['OMEGA AB-009 - DRIVER ADAPTATION AND COMPATIBILITY','CROSS-0 | offline static comparison',f'Input: {run.relative_to(root)}',f'Verified files: {len(files)}; missing: {len(missing)}',*missing,'','SYMBOL COMPARISON (occurrences, not definitions or runtime proof)'] for s,refs in symbols.items(): report.append(f'\n{s}: upstream={sum(x[0]=="linux-v6.14" for x in refs)}, Core46={sum(x[0]=="intel-core46" for x in refs)}') for src,file,n,text in refs[:16]: report.append(f' {src} {file}:{n} {text}') if len(refs)>16: report.append(' Additional references in original sources/context.') report.extend(['','BUILD AND INTERFACE EVIDENCE']) for h in hits: if 'build_dependencies' in h['topics'] or ('interface_requirements' in h['topics'] and h['file']=='mvm/vendor-cmd.c' and 1735<=h['line']<=1785): report.append(f"{h['source']} {h['file']}:{h['line']} {h['text']} | guards: {h['guards'] or '(none tracked)'}") report.extend(['','ADAPTATION REVIEW CHECKLIST','1. Trace registration, state, notification dispatch, buffer ownership and cleanup together.','2. Locate the definition and payload of iwl_mvm_send_csi_cmd; an absent definition in this sample is unresolved.','3. Resolve numeric vendor identifiers and attribute definitions; headers outside the sample may be needed.','4. Compare kernel vendor-event APIs, locking, buffer lifetime, build rules and conditional guards.','5. Confirm exact Ubuntu source/config and firmware capability bits before selecting a porting route.','6. Evaluate existing supported CSI implementations before writing a custom port.','7. Determine the actual CSI registration flags from the complete command entry, not nearby unrelated entries.','','LIMITATIONS','Lexical matches and guard tracking are not a compiler or call graph. No complete kernel tree, exact Ubuntu build, firmware binary, or live HP available. No compatibility, ABI decoding, or monitor-mode conclusion is certified. No driver built, installed, or executed. No checkpoint or ZIP refresh. Exodus deferred.']) dest=out/'AB-009-Compatibility-Report.txt'; dest.write_text('\n'.join(report)+'\n',encoding='utf-8') print(f'AB-009: {len(hits)} candidate lines | {len(files)} verified inputs | {len(missing)} missing') print('Report:',dest); print('Context:',out/'AB-009-Source-Context.txt'); print('Exodus NOT deployed; ZIP unchanged.') if __name__=='__main__': main()