Files
QualcommWireless/QualcommWifi/QualcommWifi.hpp
T
Erwan a10e097a7e feat(tahoe): port QualcommWireless & QualcommWifi to macOS Tahoe 26.x (Darwin 25)
Breakthroughs & Reverse Engineering (macOS Tahoe 26.7.1 / Darwin 25.6.0):
- Reconstructed the complete 463-slot Skywalk vtable and class layout (0x128 / 296 bytes) of IO80211Controller (__ZTV17IO80211Controller at 0xffffff8002461148) and AppleBCMWLANCore from BootKernelExtensions.kc (IO80211Family 1200.13.1, source 1566.5).
- Verified IOUSBHostDevice::deviceRequest vtable slot in Tahoe's BootKernelExtensions.kc (__ZTV15IOUSBHostDevice at 0xffffff8002e72720): confirmed exact match at slot 374 (0x176, byte offset 0xbb0).
- Disassembled Tahoe's /usr/sbin/bluetoothd (FindTransportType at 0x10014c700, Found_USB_Dongle at 0x1000e9559, GetProductAndVendorID at 0x1000edf2a) confirming USB transport matching on 'Bluetooth USB Host Controller' and CSR 0x0a12 descriptor spoofing.

Code & Build Modifications (v1.1.0):
- IO80211Controller.h: Add full 463-slot Tahoe Skywalk vtable declaration (slots 394..462, offsets 0xc50..0xe70) and exact 0x80 filler size when __IO80211_TARGET >= 260000 while preserving legacy compatibility.
- QualcommWifi.hpp/.cpp: Implement Tahoe IO80211Controller pure virtual methods (isCommandProhibited, handleCardSpecific, getDRIVER_VERSION, getHARDWARE_VERSION, getCARD_CAPABILITIES, getPOWER, setPOWER, getCOUNTRY_CODE, setCOUNTRY_CODE, setGET_DEBUG_INFO, getLogger, getFaultReporterFromDriver) and guard un-reserved IONetworkController slots 6..7 on SDK 26.5.
- QualcommWireless.cpp: Add non-null vtable slot sanity check prior to installing the shadow vtable hook on IOUSBHostDevice::deviceRequest.
- project.pbxproj & Info.plist: Upgrade to Xcode 26.6 (MacOSX26.5.sdk), MACOSX_DEPLOYMENT_TARGET = 26.0, __IO80211_TARGET = 260000, and bump version to 1.1.0.
- docs & README: Document macOS Tahoe (Darwin 25) architecture, bluetoothd offsets, and Skywalk IO80211Controller ABI.
2026-10-16 02:41:25 +02:00

278 lines
11 KiB
C++

#ifndef _QUALCOMMWIFI_HPP
#define _QUALCOMMWIFI_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#include <IOKit/IOService.h>
#include <IOKit/pci/IOPCIDevice.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
// Registres PCIe et constantes de fenêtrage (ath12k/pci.h)
#define ATH12K_PCI_SOC_GLOBAL_RESET 0x3008
#define ATH12K_PCI_WINDOW_REG_ADDRESS 0x310c
#define ATH12K_PCI_WINDOW_ENABLE_BIT 0x40000000
#define ATH12K_PCI_WINDOW_START 0x80000
#define ATH12K_PCI_WINDOW_RANGE_MASK 0x7FFFF
#define ATH12K_PCI_WINDOW_SHIFT 19
#define ATH12K_PCI_WINDOW_VALUE_MASK 0x3F
// Registre de révision matérielle du SoC Qualcomm WCN7850
#define TCSR_SOC_HW_VERSION 0x1B00000
#define TCSR_SOC_HW_VERSION_MAJOR_MASK 0x0F00
#define TCSR_SOC_HW_VERSION_MAJOR_SHIFT 8
#define TCSR_SOC_HW_VERSION_MINOR_MASK 0x00FF
// Masque DMA 36-bit aligné sur 4 Ko (4096 octets) exigé par WCN7850
#define ATH12K_DMA_MASK_36BIT_PAGE 0x0000000FFFFFF000ULL
#define ATH12K_DMA_TEST_RING_SIZE 65536 // 64 Ko pour le contexte MHI
// Registres MHI MMIO (bar0 direct)
#define ATH12K_MHI_MHIREGLEN 0x00
#define ATH12K_MHI_MHIVER 0x08
#define ATH12K_MHI_MHICFG 0x10
#define ATH12K_MHI_CHDBOFF 0x18
#define ATH12K_MHI_ERDBOFF 0x20
#define ATH12K_MHI_BHIOFF 0x28
#define ATH12K_MHI_BHIEOFF 0x2c
#define ATH12K_MHI_DEBUGOFF 0x30
#define ATH12K_MHI_MHICTRL 0x38
#define ATH12K_MHI_MHISTATUS 0x48
#define ATH12K_MHI_CCABAP_LOWER 0x58
#define ATH12K_MHI_CCABAP_HIGHER 0x5c
#define ATH12K_MHI_ECABAP_LOWER 0x60
#define ATH12K_MHI_ECABAP_HIGHER 0x64
#define ATH12K_MHI_CRCBAP_LOWER 0x68
#define ATH12K_MHI_CRCBAP_HIGHER 0x6c
#define ATH12K_MHI_CRDB_LOWER 0x70
#define ATH12K_MHI_CRDB_HIGHER 0x74
#define ATH12K_MHI_MHICTRLBASE_LOWER 0x80
#define ATH12K_MHI_MHICTRLBASE_HIGHER 0x84
#define ATH12K_MHI_MHICTRLLIMIT_LOWER 0x88
#define ATH12K_MHI_MHICTRLLIMIT_HIGHER 0x8c
#define ATH12K_MHI_MHIDATABASE_LOWER 0x98
#define ATH12K_MHI_MHIDATABASE_HIGHER 0x9c
#define ATH12K_MHI_MHIDATALIMIT_LOWER 0xa0
#define ATH12K_MHI_MHIDATALIMIT_HIGHER 0xa4
// États MHI
#define ATH12K_MHI_STATE_RESET 0x0
#define ATH12K_MHI_STATE_READY 0x1
#define ATH12K_MHI_STATE_M0 0x2
#define ATH12K_MHI_STATE_M1 0x3
#define ATH12K_MHI_STATE_M2 0x4
#define ATH12K_MHI_STATE_M3 0x5
// Environnements d'exécution MHI (EE)
#define ATH12K_MHI_EE_PBL 0x00
#define ATH12K_MHI_EE_SBL 0x01
#define ATH12K_MHI_EE_AMSS 0x02
#define ATH12K_MHI_EE_RDDM 0x03
#define ATH12K_MHI_EE_WFW 0x04
#define ATH12K_MHISTATUS_READY_MASK 0x00000001
#define ATH12K_MHICTRL_RESET_MASK 0x00000002
#define ATH12K_MHICTRL_MHISTATE_SHIFT 8
#define ATH12K_MHICTRL_MHISTATE_MASK 0x0000FF00
#define ATH12K_MHISTATUS_MHISTATE_SHIFT 8
#define ATH12K_MHISTATUS_MHISTATE_MASK 0x0000FF00
#define ATH12K_MHICFG_NER_MASK 0x00FF0000
#define ATH12K_MHICFG_NHWER_MASK 0xFF000000
// Types de paquets d'événements MHI
#define ATH12K_MHI_PKT_TYPE_STATE_CHANGE_EVENT 0x20
#define ATH12K_MHI_PKT_TYPE_EE_EVENT 0x40
// Registres BHI (Boot Host Interface)
#define ATH12K_BHI_BHIVERSION_MINOR 0x00
#define ATH12K_BHI_BHIVERSION_MAJOR 0x04
#define ATH12K_BHI_IMGADDR_LOW 0x08
#define ATH12K_BHI_IMGADDR_HIGH 0x0c
#define ATH12K_BHI_IMGSIZE 0x10
#define ATH12K_BHI_IMGTXDB 0x18
#define ATH12K_BHI_EXECENV 0x28
#define ATH12K_BHI_STATUS 0x2c
#define ATH12K_BHI_ERRCODE 0x30
#define ATH12K_BHI_SERIALNU 0x40
#define ATH12K_BHI_STATUS_RESET 0x00
#define ATH12K_BHI_STATUS_MASK 0xC0000000
#define ATH12K_BHI_STATUS_SHIFT 30
#define ATH12K_BHI_STATUS_SUCCESS 0x02
#define ATH12K_BHI_STATUS_ERROR 0x03
// Registres BHIe (Boot Host Interface extension) - offsets relatifs à bhieOff (0x224 sur WCN7850)
#define ATH12K_BHIE_MSMSOCID 0x00
#define ATH12K_BHIE_TXVECADDR_LOW 0x2c
#define ATH12K_BHIE_TXVECADDR_HIGH 0x30
#define ATH12K_BHIE_TXVECSIZE 0x34
#define ATH12K_BHIE_TXVECDB 0x3c
#define ATH12K_BHIE_TXVECSTATUS 0x44
#define ATH12K_BHIE_RXVECADDR_LOW 0x60
#define ATH12K_BHIE_RXVECADDR_HIGH 0x64
#define ATH12K_BHIE_RXVECSIZE 0x68
#define ATH12K_BHIE_RXVECDB 0x70
#define ATH12K_BHIE_RXVECSTATUS 0x78
#define ATH12K_BHIE_TXVECSTATUS_STATUS_MASK 0xC0000000
#define ATH12K_BHIE_TXVECSTATUS_STATUS_SHIFT 30
#define ATH12K_BHIE_TXVECSTATUS_XFER_COMPL 0x02
struct bhi_vec_entry {
uint64_t dma_addr;
uint64_t size;
} __attribute__((packed));
struct mhi_chan_ctxt {
UInt32 chcfg;
UInt32 chtype;
UInt32 erindex;
UInt64 rbase __attribute__((packed, aligned(4)));
UInt64 rlen __attribute__((packed, aligned(4)));
UInt64 rp __attribute__((packed, aligned(4)));
UInt64 wp __attribute__((packed, aligned(4)));
} __attribute__((packed));
struct mhi_event_ctxt {
UInt32 intmod;
UInt32 ertype;
UInt32 msivec;
UInt64 rbase __attribute__((packed, aligned(4)));
UInt64 rlen __attribute__((packed, aligned(4)));
UInt64 rp __attribute__((packed, aligned(4)));
UInt64 wp __attribute__((packed, aligned(4)));
} __attribute__((packed));
struct mhi_cmd_ctxt {
UInt32 reserved0;
UInt32 reserved1;
UInt32 reserved2;
UInt64 rbase __attribute__((packed, aligned(4)));
UInt64 rlen __attribute__((packed, aligned(4)));
UInt64 rp __attribute__((packed, aligned(4)));
UInt64 wp __attribute__((packed, aligned(4)));
} __attribute__((packed));
struct mhi_ring_element {
UInt64 ptr;
UInt32 dword[2];
} __attribute__((packed));
#define MHI_TRE_GET_EV_TYPE(tre) (((tre)->dword[1] >> 16) & 0xFF)
#define MHI_TRE_GET_EV_STATE(tre) (((tre)->dword[0] >> 24) & 0xFF)
#define MHI_TRE_GET_EV_EXECENV(tre) (((tre)->dword[0] >> 24) & 0xFF)
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <IOKit/network/IOOutputQueue.h>
#include <IOKit/network/IONetworkMedium.h>
#include <IOKit/80211/apple80211_var.h>
#include <IOKit/80211/apple80211_ioctl.h>
#include <IOKit/80211/IO80211Controller.h>
#include <IOKit/80211/IO80211Interface.h>
#include <IOKit/80211/IO80211SkywalkInterface.h>
#include "Firmware_WCN7850_Wifi.h"
class QualcommWifi : public IO80211Controller {
OSDeclareDefaultStructors(QualcommWifi)
private:
IOPCIDevice *fPciDevice;
IOMemoryMap *fBar0Map;
volatile void *fBar0Virt;
UInt32 fCurrWindow;
IOInterruptEventSource *fInterruptSource;
IO80211Interface *fNetif;
IOEthernetAddress fMacAddress;
// État réseau Wi-Fi
bool fLinkActive;
UInt16 fCurrentChannel;
SInt32 fLastRssi;
UInt8 fSsid[APPLE80211_MAX_SSID_LEN];
UInt32 fSsidLen;
UInt8 fBssid[6];
bool fScanInProgress;
// Tampon DMA physiquement contigu
IOBufferMemoryDescriptor *fDmaBuf;
IOPhysicalAddress fDmaPhysAddr;
void *fDmaVirtAddr;
bool fDmaPrepared;
UInt32 read32(UInt32 offset);
void write32(UInt32 offset, UInt32 value);
void selectWindow(UInt32 offset);
UInt32 socRead32(UInt32 offset);
void socWrite32(UInt32 offset, UInt32 value);
bool allocDmaContext(IOByteCount size);
void freeDmaContext(void);
bool loadBhiFirmware(void);
static void interruptOccurred(OSObject *owner, IOInterruptEventSource *src, int count);
public:
virtual bool init(OSDictionary *dictionary = 0) override;
virtual void free(void) override;
virtual IOService *probe(IOService *provider, SInt32 *score) override;
virtual bool start(IOService *provider) override;
virtual void stop(IOService *provider) override;
// IOEthernetController / IONetworkController interface
virtual IOReturn getHardwareAddress(IOEthernetAddress *addrP) override;
virtual IOReturn enable(IONetworkInterface *netif) override;
virtual IOReturn disable(IONetworkInterface *netif) override;
virtual UInt32 outputPacket(mbuf_t m, void *param) override;
// IO80211Controller interface
SInt32 handleApple80211Request(unsigned int req_type, int req_val, void* req_data);
#if __IO80211_TARGET >= 260000
// macOS Tahoe 26.x (Darwin 25) Skywalk IO80211Controller overrides
virtual bool isCommandProhibited(int command) override;
virtual IOReturn handleCardSpecific(IO80211SkywalkInterface *iface, unsigned long req_type, void *req_data, bool isSet) override;
virtual UInt32 hardwareOutputQueueDepth(void) override;
virtual SInt32 performCountryCodeOperation(IO80211CountryCodeOp op) override;
virtual void dataLinkLayerAttachComplete(void) override;
virtual SInt32 enableFeature(IO80211FeatureCode code, void *arg) override;
virtual IOReturn getDRIVER_VERSION(IO80211SkywalkInterface *iface, apple80211_version_data *vd) override;
virtual IOReturn getHARDWARE_VERSION(IO80211SkywalkInterface *iface, apple80211_version_data *vd) override;
virtual IOReturn getCARD_CAPABILITIES(IO80211SkywalkInterface *iface, apple80211_capability_data *cap) override;
virtual IOReturn getPOWER(IO80211SkywalkInterface *iface, apple80211_power_data *pwr) override;
virtual IOReturn setPOWER(IO80211SkywalkInterface *iface, apple80211_power_data *pwr) override;
virtual IOReturn getCOUNTRY_CODE(IO80211SkywalkInterface *iface, apple80211_country_code_data *cc) override;
virtual IOReturn setCOUNTRY_CODE(IO80211SkywalkInterface *iface, apple80211_country_code_data *cc) override;
virtual IOReturn setGET_DEBUG_INFO(IO80211SkywalkInterface *iface, apple80211_debug_command *dbg) override;
virtual void* getLogger(void) const override;
virtual void* getFaultReporterFromDriver(void) override;
#else
virtual SInt32 apple80211Request(unsigned int req_type, int req_val, IO80211Interface* iface, void* req_data) override;
virtual SInt32 apple80211SkywalkRequest(UInt req_type, int req_val, IO80211SkywalkInterface *iface, void *req_data) override;
virtual SInt32 stopDMA() override;
virtual UInt32 hardwareOutputQueueDepth(IO80211Interface* iface) override;
virtual SInt32 performCountryCodeOperation(IO80211Interface* iface, IO80211CountryCodeOp op) override;
virtual SInt32 enableFeature(IO80211FeatureCode code, void* arg) override;
virtual IOReturn enable(IO80211SkywalkInterface *netif) override;
virtual IOReturn disable(IO80211SkywalkInterface *netif) override;
#endif
// Compatibilité symboles virtuels IONetworkController sous macOS 15+ / 26+
virtual void _RESERVEDIONetworkController2() override {}
virtual void _RESERVEDIONetworkController3() override {}
virtual void _RESERVEDIONetworkController4() override {}
virtual void _RESERVEDIONetworkController5() override {}
#if __IO80211_TARGET < 260000
virtual void _RESERVEDIONetworkController6() override {}
virtual void _RESERVEDIONetworkController7() override {}
#endif
};
#endif