├── .github ├── ISSUE_TEMPLATE │ └── Bug.md └── workflows │ └── main.yml ├── .gitignore ├── AirportItlwm ├── AirportAWDL.cpp ├── AirportItlwm-Monterey-Info.plist ├── AirportItlwm-Sonoma-Info.plist ├── AirportItlwm.cpp ├── AirportItlwm.hpp ├── AirportItlwmEthernetInterface.cpp ├── AirportItlwmEthernetInterface.hpp ├── AirportItlwmInterface.cpp ├── AirportItlwmInterface.hpp ├── AirportItlwmSkywalkInterface.cpp ├── AirportItlwmSkywalkInterface.hpp ├── AirportItlwmV2.cpp ├── AirportItlwmV2.hpp ├── AirportSTAIOCTL.cpp ├── AirportVirtualIOCTL.cpp ├── IOPCIEDeviceWrapper.cpp ├── IOPCIEDeviceWrapper.hpp └── Info.plist ├── LICENSE ├── README.md ├── include ├── Airport │ ├── Apple80211.h │ ├── CCDataPipe.h │ ├── CCLogPipe.h │ ├── CCLogStream.h │ ├── CCPipe.h │ ├── CCStream.h │ ├── IO80211Controller.h │ ├── IO80211ControllerV2.h │ ├── IO80211InfraInterface.h │ ├── IO80211InfraProtocol.h │ ├── IO80211Interface.h │ ├── IO80211P2PInterface.h │ ├── IO80211SkywalkInterface.h │ ├── IO80211VirtualInterface.h │ ├── IO80211WorkLoop.h │ ├── IO80211WorkQueue.h │ ├── IOSkywalkEthernetInterface.h │ ├── IOSkywalkInterface.h │ ├── IOSkywalkLegacyEthernetInterface.h │ ├── IOSkywalkLogicalLink.h │ ├── IOSkywalkNetworkInterface.h │ ├── IOSkywalkNetworkPacket.h │ ├── IOSkywalkPacketBufferPool.h │ ├── apple80211_ioctl.h │ ├── apple80211_var.h │ ├── apple80211_wps.h │ ├── apple_private_spi.h │ └── debug.h ├── ClientKit │ ├── Common.h │ └── IoctlId.h ├── FwData.h └── HAL │ ├── ItlDriverController.hpp │ ├── ItlDriverInfo.hpp │ ├── ItlHalService.cpp │ └── ItlHalService.hpp ├── itl80211 ├── Info.plist ├── compat.cpp ├── compat.h ├── linux │ ├── bitfield.h │ ├── kernel.h │ ├── random.h │ └── types.h ├── openbsd │ ├── crypto │ │ ├── aes.c │ │ ├── aes.h │ │ ├── arc4.c │ │ ├── arc4.h │ │ ├── blf.c │ │ ├── blf.h │ │ ├── cast.c │ │ ├── cast.h │ │ ├── castsb.h │ │ ├── chacha_private.h │ │ ├── chachapoly.c │ │ ├── chachapoly.h │ │ ├── cmac.c │ │ ├── cmac.h │ │ ├── cryptodev.h │ │ ├── des_locl.h │ │ ├── ecb3_enc.c │ │ ├── ecb_enc.c │ │ ├── gmac.c │ │ ├── gmac.h │ │ ├── hmac.c │ │ ├── hmac.h │ │ ├── idgen.c │ │ ├── idgen.h │ │ ├── key_wrap.c │ │ ├── key_wrap.h │ │ ├── md5.c │ │ ├── md5.h │ │ ├── michael.c │ │ ├── michael.h │ │ ├── podd.h │ │ ├── poly1305.c │ │ ├── poly1305.h │ │ ├── rijndael.c │ │ ├── rijndael.h │ │ ├── rmd160.c │ │ ├── rmd160.h │ │ ├── set_key.c │ │ ├── sha1-pbkdf2.c │ │ ├── sha1.c │ │ ├── sha1.h │ │ ├── sha2.c │ │ ├── sha2.h │ │ ├── sk.h │ │ └── spr.h │ ├── net80211 │ │ ├── CTimeout.cpp │ │ ├── _string.c │ │ ├── ieee80211.c │ │ ├── ieee80211.h │ │ ├── ieee80211_amrr.c │ │ ├── ieee80211_amrr.h │ │ ├── ieee80211_crypto.c │ │ ├── ieee80211_crypto.h │ │ ├── ieee80211_crypto_bip.c │ │ ├── ieee80211_crypto_ccmp.c │ │ ├── ieee80211_crypto_tkip.c │ │ ├── ieee80211_crypto_wep.c │ │ ├── ieee80211_input.c │ │ ├── ieee80211_ioctl.c │ │ ├── ieee80211_ioctl.h │ │ ├── ieee80211_mira.c │ │ ├── ieee80211_mira.h │ │ ├── ieee80211_node.c │ │ ├── ieee80211_node.h │ │ ├── ieee80211_output.c │ │ ├── ieee80211_pae_input.c │ │ ├── ieee80211_pae_output.c │ │ ├── ieee80211_priv.h │ │ ├── ieee80211_proto.c │ │ ├── ieee80211_proto.h │ │ ├── ieee80211_ra.c │ │ ├── ieee80211_ra.h │ │ ├── ieee80211_radiotap.h │ │ ├── ieee80211_regdomain.c │ │ ├── ieee80211_regdomain.h │ │ ├── ieee80211_rssadapt.c │ │ ├── ieee80211_rssadapt.h │ │ ├── ieee80211_var.h │ │ └── timeout.c │ └── sys │ │ ├── CTimeout.hpp │ │ ├── _arc4random.h │ │ ├── _buf.h │ │ ├── _clock.h │ │ ├── _if_ether.h │ │ ├── _if_media.h │ │ ├── _ifq.cpp │ │ ├── _ifq.h │ │ ├── _malloc.h │ │ ├── _mbuf.cpp │ │ ├── _mbuf.h │ │ ├── _netstat.h │ │ ├── _null.h │ │ ├── _task.cpp │ │ ├── _task.h │ │ ├── arp.c │ │ ├── arp.h │ │ ├── endian.h │ │ ├── pcireg.h │ │ ├── timeout.h │ │ └── tree.h ├── zutil.c └── zutil.h ├── itlwm.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ ├── AirportItlwm (all).xcscheme │ └── itlwm.xcscheme ├── itlwm ├── Info.plist ├── ItlNetworkUserClient.cpp ├── ItlNetworkUserClient.hpp ├── PrivateSPI.pch ├── firmware │ ├── iwlwifi-Qu-b0-hr-b0-68.ucode │ ├── iwlwifi-Qu-b0-jf-b0-68.ucode │ ├── iwlwifi-Qu-c0-hr-b0-68.ucode │ ├── iwlwifi-Qu-c0-jf-b0-68.ucode │ ├── iwlwifi-QuZ-a0-hr-b0-68.ucode │ ├── iwlwifi-QuZ-a0-jf-b0-68.ucode │ ├── iwlwifi-cc-a0-68.ucode │ ├── iwlwifi-so-a0-gf-a0-68.ucode │ ├── iwlwifi-so-a0-gf-a0.pnvm │ ├── iwlwifi-so-a0-gf4-a0-68.ucode │ ├── iwlwifi-so-a0-gf4-a0.pnvm │ ├── iwlwifi-so-a0-hr-b0-68.ucode │ ├── iwlwifi-so-a0-jf-b0-68.ucode │ ├── iwlwifi-ty-a0-gf-a0-68.ucode │ ├── iwlwifi-ty-a0-gf-a0.pnvm │ ├── iwm-3160-17 │ ├── iwm-3168-29 │ ├── iwm-7260-17 │ ├── iwm-7265-17 │ ├── iwm-8000C-36 │ ├── iwm-8265-36 │ ├── iwm-9000-46 │ ├── iwm-9260-46 │ ├── iwn-1000 │ ├── iwn-105 │ ├── iwn-135 │ ├── iwn-2000 │ ├── iwn-2030 │ ├── iwn-4965 │ ├── iwn-5000 │ ├── iwn-5150 │ ├── iwn-6000 │ ├── iwn-6005 │ ├── iwn-6030 │ └── iwn-6050 ├── hal_iwm │ ├── ItlIwm.cpp │ ├── ItlIwm.hpp │ ├── coex.cpp │ ├── ctxt.cpp │ ├── fw.cpp │ ├── hw.cpp │ ├── if_iwmreg.h │ ├── if_iwmvar.h │ ├── io.cpp │ ├── itlhdr.h │ ├── led.cpp │ ├── mac80211.cpp │ ├── nvm.cpp │ ├── phy.cpp │ ├── power.cpp │ ├── rs.cpp │ ├── rs.h │ ├── rx.cpp │ ├── scan.cpp │ ├── tx.cpp │ └── utils.cpp ├── hal_iwn │ ├── ItlIwn.cpp │ ├── ItlIwn.hpp │ ├── if_iwnreg.h │ └── if_iwnvar.h ├── hal_iwx │ ├── ItlIwx.cpp │ ├── ItlIwx.hpp │ ├── if_iwxreg.h │ └── if_iwxvar.h ├── itlwm.cpp ├── itlwm.hpp └── pm.cpp ├── iwlwifi-firmware-license └── scripts ├── fw_gen.sh ├── load.sh ├── unload.sh └── zlib_compress_fw.py /.github/ISSUE_TEMPLATE/Bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a bug 4 | labels: '' 5 | assignees: '' 6 | --- 7 | 8 | 9 | 10 | **Have You Read Our Docs** 11 | 12 | 13 | **Are You Reporting A Bug** 14 | 15 | 16 | **Environment** 17 | 18 | - Kext Version: 19 | - WiFi Card Model: 20 | - PCI Product ID: 21 | - macOS Version: 22 | 23 | **Description** 24 | 25 | 26 | **Bug Report Archive** 27 | 28 | 29 | 30 | **Kext Download Source** 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CD 2 | 3 | on: 4 | push: 5 | branches: master 6 | 7 | env: 8 | BUILD_OUTPUT: 'build/Build/Products/Debug' 9 | 10 | jobs: 11 | 12 | build: 13 | 14 | runs-on: macos-latest 15 | 16 | steps: 17 | 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: '5' 21 | 22 | - name: Manage Version 23 | run: | 24 | git fetch --prune --unshallow --tags 25 | GIT_SHA="$(git rev-parse --short HEAD)" 26 | CUR_TAG="$(git tag -l | grep 'alpha\|beta' | tail -1)" 27 | eval $(grep -m 1 "MODULE_VERSION =" itlwm.xcodeproj/project.pbxproj | tr -d ';' | tr -d '\t' | tr -d " ") 28 | echo "SHORT_SHA=$GIT_SHA" >> $GITHUB_ENV 29 | echo "ITLWM_VER=$MODULE_VERSION" >> $GITHUB_ENV 30 | if [[ -z $CUR_TAG ]]; then 31 | echo "OLD_PRE_TAG=NULL" >> $GITHUB_ENV 32 | else 33 | echo "OLD_PRE_TAG=$CUR_TAG" >> $GITHUB_ENV 34 | fi 35 | 36 | - name: Install MacKernelSDK 37 | run: | 38 | git clone --depth=1 https://github.com/acidanthera/MacKernelSDK.git 39 | 40 | - name: Build itlwm 41 | run: | 42 | xcodebuild -scheme itlwm -configuration Debug -derivedDataPath build GIT_COMMIT=_${SHORT_SHA} | xcpretty && exit ${PIPESTATUS[0]} 43 | 44 | - name: Build AirportItlwm 45 | run: | 46 | xcodebuild -scheme "AirportItlwm (all)" -configuration Debug -derivedDataPath build GIT_COMMIT=_${SHORT_SHA} | xcpretty && exit ${PIPESTATUS[0]} 47 | 48 | - name: Pack Artifacts 49 | run: | 50 | cd $BUILD_OUTPUT 51 | zip -r itlwm-v${ITLWM_VER}-DEBUG-alpha-${SHORT_SHA}.zip itlwm.kext 52 | while read -r tgt ; do 53 | zip -r AirportItlwm-${tgt// /_}-v${ITLWM_VER}-DEBUG-alpha-${SHORT_SHA}.zip "$tgt" 54 | done < <(find . -mindepth 1 -maxdepth 1 -type d -not -path "*.kext" | cut -c 3-) 55 | cd - 56 | 57 | - name: Generate Prerelease Release Notes 58 | run: | 59 | echo '### Disclaimer:' >> ReleaseNotes.md 60 | echo '***This alpha version is for testing only.***' >> ReleaseNotes.md 61 | echo 'It is not ready for daily use and we do not guarantee its usability.' >> ReleaseNotes.md 62 | echo 'If you discovered an issue and you do not have debugging skills, please check with the [Gitter Chat Room](https://gitter.im/OpenIntelWireless/itlwm) in advance before opening an Issue.' >> ReleaseNotes.md 63 | echo '### The latest five updates are:' >> ReleaseNotes.md 64 | git log -"5" --format="- %H %s" | sed '/^$/d' >> ReleaseNotes.md 65 | 66 | - name: Delete Old Prerelease 67 | uses: dev-drprasad/delete-tag-and-release@v0.2.1 68 | with: 69 | tag_name: ${{ env.OLD_PRE_TAG }} 70 | env: 71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 72 | 73 | - name: Publish GitHub Release 74 | if: contains(github.event.head_commit.message, 'Bump version') == false 75 | uses: ncipollo/release-action@v1.12.0 76 | with: 77 | prerelease: true 78 | bodyFile: ReleaseNotes.md 79 | artifacts: "${{ env.BUILD_OUTPUT }}/*.zip" 80 | tag: "v${{ env.ITLWM_VER }}-alpha" 81 | token: ${{ secrets.GITHUB_TOKEN }} 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | DerivedData 3 | build 4 | xcuserdata 5 | project.xcworkspace 6 | FwBinary.cpp 7 | *.pyc 8 | MacKernelSDK 9 | -------------------------------------------------------------------------------- /AirportItlwm/AirportAWDL.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AirportAWDL.cpp 3 | // AirportItlwm 4 | // 5 | // Created by qcwap on 2020/9/4. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #include "AirportItlwm.hpp" 10 | 11 | #include 12 | #include 13 | 14 | #define INTERFACE_NAME(object) \ 15 | OSDynamicCast(IO80211Interface, object) == nullptr ? (OSDynamicCast(IO80211P2PInterface, object) == nullptr ? "???" : OSDynamicCast(IO80211P2PInterface, object)->getBSDName()) : OSDynamicCast(IO80211Interface, object)->getBSDName() 16 | 17 | IOReturn AirportItlwm:: 18 | getIE(OSObject *object, struct apple80211_ie_data *data) 19 | { 20 | XYLog("%s %s Error\n", __FUNCTION__, INTERFACE_NAME(object)); 21 | return kIOReturnError; 22 | } 23 | 24 | IOReturn AirportItlwm:: 25 | setIE(OSObject *object, struct apple80211_ie_data *data) 26 | { 27 | XYLog("%s %s frame_type_flags %x add %d signature_len %d ie_len %d\n", __FUNCTION__, INTERFACE_NAME(object), data->frame_type_flags, data->add, data->signature_len, data->ie_len); 28 | if (data->frame_type_flags == APPLE80211_IE_FLAG_ASSOC_REQ && data->add && data->ie_len && *(uint8_t*)data->ie == 68) { 29 | XYLog("%s setCustomAssocIE\n", __FUNCTION__); 30 | return kIOReturnSuccess; 31 | } 32 | 33 | return kIOReturnSuccess; 34 | } 35 | 36 | IOReturn AirportItlwm:: 37 | setP2P_SCAN(OSObject *object, struct apple80211_scan_data *data) 38 | { 39 | XYLog("%s %s ssid=%s bssid=%s channel=%d phy_mode=%d scan_type=%d\n", __FUNCTION__, INTERFACE_NAME(object), data->ssid, ether_sprintf(data->bssid.octet), data->num_channels, data->phy_mode, data->scan_type); 40 | 41 | return kIOReturnSuccess; 42 | } 43 | 44 | IOReturn AirportItlwm:: 45 | setP2P_LISTEN(OSObject *object, struct apple80211_p2p_listen_data *data) 46 | { 47 | XYLog("%s %s channel=%d pad1=%d flags=%d duration=%d\n", __FUNCTION__, INTERFACE_NAME(object), data->channel, data->pad1, data->flags, data->duration); 48 | 49 | return kIOReturnSuccess; 50 | } 51 | 52 | IOReturn AirportItlwm:: 53 | setP2P_GO_CONF(OSObject *object, struct apple80211_p2p_go_conf_data *data) 54 | { 55 | XYLog("%s %s auth_upper=%d auth_lower=%d channel=%d bcn_len=%d ssid=%s suppress_beacon=%d\n", __FUNCTION__, INTERFACE_NAME(object), data->auth_upper, data->auth_lower, data->channel, data->bcn_len, data->ssid, data->suppress_beacon); 56 | 57 | return kIOReturnSuccess; 58 | } 59 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwm-Monterey-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MODULE_VERSION) 19 | CFBundleVersion 20 | $(MODULE_VERSION) 21 | IOKitPersonalities 22 | 23 | itlwm 24 | 25 | CFBundleIdentifier 26 | com.zxystd.AirportItlwm 27 | IOClass 28 | AirportItlwm 29 | IOMatchCategory 30 | IODefaultMatchCategory 31 | IOPCIMatch 32 | 0x27238086 0x43F08086 0xA0F08086 0x34F08086 0x4DF08086 0x02F08086 0x3DF08086 0x06F08086 0x27208086 0x08b18086 0x08b28086 0x08b38086 0x08b48086 0x095a8086 0x095b8086 0x31658086 0x31668086 0x24f38086 0x24f48086 0x24f58086 0x24f68086 0x24fb8086 0x24fd8086 0x25268086 0x9df08086 0xa3708086 0x31DC8086 0x30DC8086 0x271C8086 0x271B8086 0x42a48086 0x00a08086 0x00a48086 0x02a08086 0x40a48086 0x00608086 0x00648086 0x02608086 0x02648086 0x42298086 0x422b8086 0x422c8086 0x42308086 0x42328086 0x42358086 0x42368086 0x42378086 0x42388086 0x42398086 0x423a8086 0x423b8086 0x423c8086 0x423d8086 0x00828086 0x00838086 0x00848086 0x00858086 0x00878086 0x00898086 0x008a8086 0x008b8086 0x00908086 0x00918086 0x08928086 0x08938086 0x08948086 0x08958086 0x08968086 0x08978086 0x08ae8086 0x08af8086 0x088e8086 0x088f8086 0x08908086 0x08918086 0x08878086 0x08888086 0x27258086 0x27268086 0x7A708086 0x7AF08086 0x51F08086 0x54F08086 0x27298086 0x7E408086 0x7F708086 0x51F18086 33 | IOProbeScore 34 | 2000 35 | IOProviderClass 36 | IOPCIDevice 37 | 38 | 39 | NSHumanReadableCopyright 40 | Copyright © 2020 钟先耀. All rights reserved. 41 | OSBundleLibraries 42 | 43 | com.apple.iokit.IO80211FamilyLegacy 44 | 600.0 45 | com.apple.iokit.IONetworkingFamily 46 | 3.2 47 | com.apple.iokit.IOPCIFamily 48 | 2.9 49 | com.apple.kpi.bsd 50 | 16.7 51 | com.apple.kpi.iokit 52 | 16.7 53 | com.apple.kpi.libkern 54 | 16.7 55 | com.apple.kpi.mach 56 | 16.7 57 | 58 | OSBundleRequired 59 | Network-Root 60 | 61 | 62 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwm-Sonoma-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MODULE_VERSION) 19 | CFBundleVersion 20 | $(MODULE_VERSION) 21 | IOKitPersonalities 22 | 23 | NetworkController 24 | 25 | CFBundleIdentifier 26 | com.zxystd.AirportItlwm 27 | IOClass 28 | AirportItlwm 29 | IOMatchCategory 30 | WiFiDriver 31 | IONetworkRootType 32 | airport 33 | IOProbeScore 34 | 70000 35 | IOProviderClass 36 | IOPCIEDeviceWrapper 37 | IOResourceMatch 38 | IOBSD 39 | 40 | itlwm 41 | 42 | CFBundleIdentifier 43 | com.zxystd.AirportItlwm 44 | IOClass 45 | IOPCIEDeviceWrapper 46 | IOPCIMatch 47 | 0x27238086 0x43F08086 0xA0F08086 0x34F08086 0x4DF08086 0x02F08086 0x3DF08086 0x06F08086 0x27208086 0x08b18086 0x08b28086 0x08b38086 0x08b48086 0x095a8086 0x095b8086 0x31658086 0x31668086 0x24f38086 0x24f48086 0x24f58086 0x24f68086 0x24fb8086 0x24fd8086 0x25268086 0x9df08086 0xa3708086 0x31DC8086 0x30DC8086 0x271C8086 0x271B8086 0x42a48086 0x00a08086 0x00a48086 0x02a08086 0x40a48086 0x00608086 0x00648086 0x02608086 0x02648086 0x42298086 0x422b8086 0x422c8086 0x42308086 0x42328086 0x42358086 0x42368086 0x42378086 0x42388086 0x42398086 0x423a8086 0x423b8086 0x423c8086 0x423d8086 0x00828086 0x00838086 0x00848086 0x00858086 0x00878086 0x00898086 0x008a8086 0x008b8086 0x00908086 0x00918086 0x08928086 0x08938086 0x08948086 0x08958086 0x08968086 0x08978086 0x08ae8086 0x08af8086 0x088e8086 0x088f8086 0x08908086 0x08918086 0x08878086 0x08888086 0x27258086 0x27268086 0x7A708086 0x7AF08086 0x51F08086 0x54F08086 0x27298086 0x7E408086 0x7F708086 0x51F18086 48 | IOProbeScore 49 | 70000 50 | IOProviderClass 51 | IOPCIDevice 52 | 53 | 54 | NSHumanReadableCopyright 55 | Copyright © 2020 钟先耀. All rights reserved. 56 | OSBundleLibraries 57 | 58 | com.apple.driver.corecapture 59 | 1.0.0 60 | com.apple.iokit.IO80211Family 61 | 1.5.0 62 | com.apple.iokit.IONetworkingFamily 63 | 3.2 64 | com.apple.iokit.IOPCIFamily 65 | 2.9 66 | com.apple.iokit.IOSkywalkFamily 67 | 1.0 68 | com.apple.kpi.bsd 69 | 16.7 70 | com.apple.kpi.iokit 71 | 16.7 72 | com.apple.kpi.libkern 73 | 16.7 74 | com.apple.kpi.mach 75 | 16.7 76 | 77 | OSBundleRequired 78 | Network-Root 79 | 80 | 81 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwmEthernetInterface.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AirportItlwmEthernetInterface.cpp 3 | // AirportItlwm-Sonoma 4 | // 5 | // Created by qcwap on 2023/6/27. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #include "AirportItlwmEthernetInterface.hpp" 10 | 11 | #include 12 | #include 13 | 14 | #define super IOEthernetInterface 15 | OSDefineMetaClassAndStructors(AirportItlwmEthernetInterface, IOEthernetInterface); 16 | 17 | bool AirportItlwmEthernetInterface:: 18 | initWithSkywalkInterfaceAndProvider(IONetworkController *controller, IO80211SkywalkInterface *interface) 19 | { 20 | bool ret = super::init(controller); 21 | if (ret) 22 | this->interface = interface; 23 | this->isAttach = false; 24 | return ret; 25 | } 26 | 27 | IOReturn AirportItlwmEthernetInterface:: 28 | attachToDataLinkLayer( IOOptionBits options, void *parameter ) 29 | { 30 | XYLog("%s\n", __FUNCTION__); 31 | char infName[IFNAMSIZ]; 32 | IOReturn ret = super::attachToDataLinkLayer(options, parameter); 33 | if (ret == kIOReturnSuccess && interface) { 34 | UInt8 builtIn = 0; 35 | IOEthernetAddress addr; 36 | interface->setProperty("built-in", OSData::withBytes(&builtIn, sizeof(builtIn))); 37 | snprintf(infName, sizeof(infName), "%s%u", ifnet_name(getIfnet()), ifnet_unit(getIfnet())); 38 | interface->setProperty("IOInterfaceName", OSString::withCString(infName)); 39 | interface->setProperty(kIOInterfaceUnit, OSNumber::withNumber(ifnet_unit(getIfnet()), 8)); 40 | interface->setProperty(kIOInterfaceNamePrefix, OSString::withCString(ifnet_name(getIfnet()))); 41 | if (OSDynamicCast(IOEthernetController, getController())->getHardwareAddress(&addr) == kIOReturnSuccess) 42 | setProperty(kIOMACAddress, (void *) &addr, 43 | kIOEthernetAddressSize); 44 | interface->registerService(); 45 | interface->prepareBSDInterface(getIfnet(), 0); 46 | // ret = bpf_attach(getIfnet(), DLT_RAW, 0x48, &AirportItlwmEthernetInterface::bpfOutputPacket, &AirportItlwmEthernetInterface::bpfTap); 47 | } 48 | isAttach = true; 49 | return ret; 50 | } 51 | 52 | void AirportItlwmEthernetInterface:: 53 | detachFromDataLinkLayer(IOOptionBits options, void *parameter) 54 | { 55 | super::detachFromDataLinkLayer(options, parameter); 56 | isAttach = false; 57 | } 58 | 59 | /** 60 | Add another hack to fake that the provider is IOSkywalkNetworkInterface, to avoid skywalkfamily instance cast panic. 61 | */ 62 | IOService *AirportItlwmEthernetInterface:: 63 | getProvider() const 64 | { 65 | return isAttach ? this->interface : super::getProvider(); 66 | } 67 | 68 | errno_t AirportItlwmEthernetInterface:: 69 | bpfOutputPacket(ifnet_t interface, u_int32_t data_link_type, mbuf_t packet) 70 | { 71 | XYLog("%s data_link_type: %d\n", __FUNCTION__, data_link_type); 72 | AirportItlwmEthernetInterface *networkInterface = (AirportItlwmEthernetInterface *)ifnet_softc(interface); 73 | return networkInterface->enqueueOutputPacket(packet); 74 | } 75 | 76 | errno_t AirportItlwmEthernetInterface:: 77 | bpfTap(ifnet_t interface, u_int32_t data_link_type, bpf_tap_mode direction) 78 | { 79 | XYLog("%s data_link_type: %d direction: %d\n", __FUNCTION__, data_link_type, direction); 80 | return 0; 81 | } 82 | 83 | bool AirportItlwmEthernetInterface:: 84 | setLinkState(IO80211LinkState state) 85 | { 86 | if (state == kIO80211NetworkLinkUp) { 87 | ifnet_set_flags(getIfnet(), ifnet_flags(getIfnet()) | (IFF_UP | IFF_RUNNING), (IFF_UP | IFF_RUNNING)); 88 | } else { 89 | ifnet_set_flags(getIfnet(), ifnet_flags(getIfnet()) & ~(IFF_UP | IFF_RUNNING), 0); 90 | } 91 | return true; 92 | } 93 | 94 | extern const char* hexdump(uint8_t *buf, size_t len); 95 | 96 | UInt32 AirportItlwmEthernetInterface:: 97 | inputPacket(mbuf_t packet, UInt32 length, IOOptionBits options, void *param) 98 | { 99 | ether_header_t *eh; 100 | size_t len = mbuf_len(packet); 101 | 102 | eh = (ether_header_t *)mbuf_data(packet); 103 | if (len >= sizeof(ether_header_t) && eh->ether_type == htons(ETHERTYPE_PAE)) { // EAPOL packet 104 | const char* dump = hexdump((uint8_t*)mbuf_data(packet), len); 105 | XYLog("input EAPOL packet, len: %zu, data: %s\n", len, dump ? dump : "Failed to allocate memory"); 106 | if (dump) 107 | IOFree((void*)dump, 3 * len + 1); 108 | } 109 | return IOEthernetInterface::inputPacket(packet, length, options, param); 110 | } 111 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwmEthernetInterface.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // AirportItlwmEthernetInterface.hpp 3 | // AirportItlwm-Sonoma 4 | // 5 | // Created by qcwap on 2023/6/27. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef AirportItlwmEthernetInterface_hpp 10 | #define AirportItlwmEthernetInterface_hpp 11 | 12 | extern "C" { 13 | #include 14 | } 15 | #include "Airport/Apple80211.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class AirportItlwmEthernetInterface : public IOEthernetInterface { 22 | OSDeclareDefaultStructors(AirportItlwmEthernetInterface) 23 | 24 | public: 25 | virtual IOReturn attachToDataLinkLayer( IOOptionBits options, 26 | void * parameter ) override; 27 | 28 | virtual void detachFromDataLinkLayer( IOOptionBits options, 29 | void * parameter ) override; 30 | 31 | virtual bool initWithSkywalkInterfaceAndProvider(IONetworkController *controller, IO80211SkywalkInterface *interface); 32 | 33 | virtual bool setLinkState(IO80211LinkState state); 34 | 35 | static errno_t bpfOutputPacket(ifnet_t interface, u_int32_t data_link_type, 36 | mbuf_t packet); 37 | 38 | static errno_t bpfTap(ifnet_t interface, u_int32_t data_link_type, 39 | bpf_tap_mode direction); 40 | 41 | virtual UInt32 inputPacket( 42 | mbuf_t packet, 43 | UInt32 length = 0, 44 | IOOptionBits options = 0, 45 | void * param = 0 ) override; 46 | 47 | virtual IOService * getProvider( void ) const override; 48 | 49 | private: 50 | IO80211SkywalkInterface *interface; 51 | bool isAttach; 52 | }; 53 | 54 | #endif /* AirportItlwmEthernetInterface_hpp */ 55 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwmInterface.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AirportItlwmInterface.cpp 3 | // AirportItlwm 4 | // 5 | // Created by qcwap on 2020/9/7. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #include "AirportItlwmInterface.hpp" 10 | 11 | #define super IO80211Interface 12 | OSDefineMetaClassAndStructors(AirportItlwmInterface, IO80211Interface); 13 | 14 | const char* hexdump(uint8_t *buf, size_t len) 15 | { 16 | ssize_t str_len = len * 3 + 1; 17 | char *str = (char*)IOMalloc(str_len); 18 | if (!str) 19 | return nullptr; 20 | for (size_t i = 0; i < len; i++) 21 | snprintf(str + 3 * i, (len - i) * 3, "%02x ", buf[i]); 22 | str[MAX(str_len - 2, 0)] = 0; 23 | return str; 24 | } 25 | 26 | bool AirportItlwmInterface:: 27 | init(IO80211Controller *controller, ItlHalService *halService) 28 | { 29 | if (!super::init(controller)) 30 | return false; 31 | this->fHalService = halService; 32 | return true; 33 | } 34 | 35 | UInt32 AirportItlwmInterface:: 36 | inputPacket(mbuf_t packet, UInt32 length, IOOptionBits options, void *param) 37 | { 38 | ether_header_t *eh; 39 | size_t len = mbuf_len(packet); 40 | 41 | eh = (ether_header_t *)mbuf_data(packet); 42 | if (len >= sizeof(ether_header_t) && eh->ether_type == htons(ETHERTYPE_PAE)) { // EAPOL packet 43 | const char* dump = hexdump((uint8_t*)mbuf_data(packet), len); 44 | XYLog("input EAPOL packet, len: %zu, data: %s\n", len, dump ? dump : "Failed to allocate memory"); 45 | if (dump) 46 | IOFree((void*)dump, 3 * len + 1); 47 | return IO80211Interface::inputPacket(packet, (UInt32)len, 0, param); 48 | } 49 | return IOEthernetInterface::inputPacket(packet, length, options, param); 50 | } 51 | -------------------------------------------------------------------------------- /AirportItlwm/AirportItlwmInterface.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // AirportItlwmInterface.hpp 3 | // AirportItlwm 4 | // 5 | // Created by qcwap on 2020/9/7. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef AirportItlwmInterface_hpp 10 | #define AirportItlwmInterface_hpp 11 | 12 | #include "Airport/Apple80211.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | class AirportItlwmInterface : public IO80211Interface { 19 | OSDeclareDefaultStructors(AirportItlwmInterface) 20 | 21 | public: 22 | virtual UInt32 inputPacket( 23 | mbuf_t packet, 24 | UInt32 length = 0, 25 | IOOptionBits options = 0, 26 | void * param = 0 ) override; 27 | 28 | bool init(IO80211Controller *controller, ItlHalService *halService); 29 | 30 | private: 31 | ItlHalService *fHalService; 32 | }; 33 | 34 | #endif /* AirportItlwmInterface_hpp */ 35 | -------------------------------------------------------------------------------- /AirportItlwm/IOPCIEDeviceWrapper.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOPCIEDeviceWrapper.cpp 3 | // AirportItlwm-Sonoma 4 | // 5 | // Created by qcwap on 2023/6/27. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #include "IOPCIEDeviceWrapper.hpp" 10 | #include "Apple80211.h" 11 | 12 | #include "ItlIwm.hpp" 13 | #include "ItlIwx.hpp" 14 | #include "ItlIwn.hpp" 15 | 16 | #define super IOService 17 | OSDefineMetaClassAndStructors(IOPCIEDeviceWrapper, IOService); 18 | 19 | #define PCI_MSI_FLAGS 2 /* Message Control */ 20 | #define PCI_CAP_ID_MSI 0x05 /* Message Signalled Interrupts */ 21 | #define PCI_MSIX_FLAGS 2 /* Message Control */ 22 | #define PCI_CAP_ID_MSIX 0x11 /* MSI-X */ 23 | #define PCI_MSIX_FLAGS_ENABLE 0x8000 /* MSI-X enable */ 24 | #define PCI_MSI_FLAGS_ENABLE 0x0001 /* MSI feature enabled */ 25 | 26 | static IOPMPowerState powerStateArray[2] = 27 | { 28 | {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 29 | {1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0} 30 | }; 31 | 32 | static void pciMsiSetEnable(IOPCIDevice *device, UInt8 msiCap, int enable) 33 | { 34 | UInt16 control; 35 | 36 | control = device->configRead16(msiCap + PCI_MSI_FLAGS); 37 | control &= ~PCI_MSI_FLAGS_ENABLE; 38 | if (enable) 39 | control |= PCI_MSI_FLAGS_ENABLE; 40 | device->configWrite16(msiCap + PCI_MSI_FLAGS, control); 41 | } 42 | 43 | static void pciMsiXClearAndSet(IOPCIDevice *device, UInt8 msixCap, UInt16 clear, UInt16 set) 44 | { 45 | UInt16 ctrl; 46 | 47 | ctrl = device->configRead16(msixCap + PCI_MSIX_FLAGS); 48 | ctrl &= ~clear; 49 | ctrl |= set; 50 | device->configWrite16(msixCap + PCI_MSIX_FLAGS, ctrl); 51 | } 52 | 53 | extern IOWorkLoop *_fWorkloop; 54 | 55 | IOWorkLoop *IOPCIEDeviceWrapper::getWorkLoop() const 56 | { 57 | return _fWorkloop; 58 | } 59 | 60 | IOService* IOPCIEDeviceWrapper:: 61 | probe(IOService *provider, SInt32 *score) 62 | { 63 | XYLog("%s\n", __PRETTY_FUNCTION__); 64 | bool isMatch = false; 65 | super::probe(provider, score); 66 | UInt8 msiCap; 67 | UInt8 msixCap; 68 | IOPCIDevice* device = OSDynamicCast(IOPCIDevice, provider); 69 | if (!device) 70 | return NULL; 71 | if (ItlIwx::iwx_match(device)) { 72 | isMatch = true; 73 | fHalService = new ItlIwx; 74 | } 75 | if (!isMatch && ItlIwm::iwm_match(device)) { 76 | isMatch = true; 77 | fHalService = new ItlIwm; 78 | } 79 | if (!isMatch && ItlIwn::iwn_match(device)) { 80 | isMatch = true; 81 | fHalService = new ItlIwn; 82 | } 83 | if (isMatch) { 84 | XYLog("%s Found\n", __FUNCTION__); 85 | device->findPCICapability(PCI_CAP_ID_MSIX, &msixCap); 86 | if (msixCap) 87 | pciMsiXClearAndSet(device, msixCap, PCI_MSIX_FLAGS_ENABLE, 0); 88 | device->findPCICapability(PCI_CAP_ID_MSI, &msiCap); 89 | if (msiCap) 90 | pciMsiSetEnable(device, msiCap, 1); 91 | if (!msiCap && !msixCap) { 92 | XYLog("%s No MSI cap\n", __FUNCTION__); 93 | fHalService->release(); 94 | fHalService = NULL; 95 | return NULL; 96 | } 97 | this->pciNub = device; 98 | return this; 99 | } 100 | return NULL; 101 | } 102 | 103 | bool IOPCIEDeviceWrapper:: 104 | start(IOService *provider) 105 | { 106 | XYLog("%s\n", __PRETTY_FUNCTION__); 107 | _fWorkloop = IO80211WorkQueue::workQueue(); 108 | if (!super::start(provider)) { 109 | return false; 110 | } 111 | IOLog("%s::super start succeed\n", getName()); 112 | UInt8 builtIn = 0; 113 | setProperty("built-in", OSData::withBytes(&builtIn, sizeof(builtIn))); 114 | PMinit(); 115 | registerPowerDriver(this, powerStateArray, 2); 116 | provider->joinPMtree(this); 117 | registerService(); 118 | return true; 119 | } 120 | 121 | void IOPCIEDeviceWrapper:: 122 | stop(IOService *provider) 123 | { 124 | XYLog("%s\n", __PRETTY_FUNCTION__); 125 | PMstop(); 126 | super::stop(provider); 127 | } 128 | 129 | IOReturn IOPCIEDeviceWrapper:: 130 | setPowerState(unsigned long powerStateOrdinal, IOService *whatDevice) 131 | { 132 | return IOPMAckImplied; 133 | } 134 | -------------------------------------------------------------------------------- /AirportItlwm/IOPCIEDeviceWrapper.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOPCIEDeviceWrapper.hpp 3 | // AirportItlwm-Sonoma 4 | // 5 | // Created by qcwap on 2023/6/27. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOPCIEDeviceWrapper_hpp 10 | #define IOPCIEDeviceWrapper_hpp 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | class IOPCIEDeviceWrapper : public IOService { 20 | OSDeclareDefaultStructors(IOPCIEDeviceWrapper) 21 | 22 | public: 23 | virtual IOService* probe(IOService* provider, SInt32* score) override; 24 | virtual bool start(IOService *provider) override; 25 | virtual void stop(IOService *provider) override; 26 | virtual IOWorkLoop* getWorkLoop() const override; 27 | virtual IOReturn setPowerState( 28 | unsigned long powerStateOrdinal, 29 | IOService * whatDevice ) override; 30 | 31 | public: 32 | ItlHalService *fHalService; 33 | IOPCIDevice *pciNub; 34 | }; 35 | 36 | #endif /* IOPCIEDeviceWrapper_hpp */ 37 | -------------------------------------------------------------------------------- /AirportItlwm/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MODULE_VERSION) 19 | CFBundleVersion 20 | $(MODULE_VERSION) 21 | IOKitPersonalities 22 | 23 | itlwm 24 | 25 | CFBundleIdentifier 26 | com.zxystd.AirportItlwm 27 | IOClass 28 | AirportItlwm 29 | IOMatchCategory 30 | IODefaultMatchCategory 31 | IOPCIMatch 32 | 0x27238086 0x43F08086 0xA0F08086 0x34F08086 0x4DF08086 0x02F08086 0x3DF08086 0x06F08086 0x27208086 0x08b18086 0x08b28086 0x08b38086 0x08b48086 0x095a8086 0x095b8086 0x31658086 0x31668086 0x24f38086 0x24f48086 0x24f58086 0x24f68086 0x24fb8086 0x24fd8086 0x25268086 0x9df08086 0xa3708086 0x31DC8086 0x30DC8086 0x271C8086 0x271B8086 0x42a48086 0x00a08086 0x00a48086 0x02a08086 0x40a48086 0x00608086 0x00648086 0x02608086 0x02648086 0x42298086 0x422b8086 0x422c8086 0x42308086 0x42328086 0x42358086 0x42368086 0x42378086 0x42388086 0x42398086 0x423a8086 0x423b8086 0x423c8086 0x423d8086 0x00828086 0x00838086 0x00848086 0x00858086 0x00878086 0x00898086 0x008a8086 0x008b8086 0x00908086 0x00918086 0x08928086 0x08938086 0x08948086 0x08958086 0x08968086 0x08978086 0x08ae8086 0x08af8086 0x088e8086 0x088f8086 0x08908086 0x08918086 0x08878086 0x08888086 0x27258086 0x27268086 0x7A708086 0x7AF08086 0x51F08086 0x54F08086 0x27298086 0x7E408086 0x7F708086 0x51F18086 33 | IOProbeScore 34 | 2000 35 | IOProviderClass 36 | IOPCIDevice 37 | 38 | 39 | NSHumanReadableCopyright 40 | Copyright © 2020 钟先耀. All rights reserved. 41 | OSBundleLibraries 42 | 43 | com.apple.iokit.IO80211Family 44 | 1200.12.2b1 45 | com.apple.iokit.IONetworkingFamily 46 | 3.2 47 | com.apple.iokit.IOPCIFamily 48 | 2.9 49 | com.apple.kpi.bsd 50 | 16.7 51 | com.apple.kpi.iokit 52 | 16.7 53 | com.apple.kpi.libkern 54 | 16.7 55 | com.apple.kpi.mach 56 | 16.7 57 | 58 | OSBundleRequired 59 | Network-Root 60 | 61 | 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # itlwm 2 | 3 | **An Intel Wi-Fi Adapter Kernel Extension for macOS, based on the OpenBSD Project.** 4 | 5 | ## Documentation 6 | 7 | We highly recommend exploring our documentation before using this Kernel Extension: 8 | 9 | - [Intro](https://OpenIntelWireless.github.io/itlwm) 10 | - [Compatibility](https://openintelwireless.github.io/itlwm/Compat) 11 | - [FAQ](https://openintelwireless.github.io/itlwm/FAQ) 12 | 13 | ## Download 14 | 15 | [![Download from https://github.com/OpenIntelWireless/itlwm/releases](https://img.shields.io/github/v/release/OpenIntelWireless/itlwm?label=Download)](https://github.com/OpenIntelWireless/itlwm/releases) 16 | 17 | ## Questions and Issues 18 | 19 | Check out our [FAQ Page](https://openintelwireless.github.io/itlwm/FAQ) for more info. 20 | 21 | If you have other questions or feedback, feel free to [![Join the chat at https://gitter.im/OpenIntelWireless/itlwm](https://badges.gitter.im/OpenIntelWireless/itlwm.svg)](https://gitter.im/OpenIntelWireless/itlwm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge). 22 | 23 | We only accept bug reports in GitHub Issues, before opening an issue, you're recommended to reconfirm it with us on [Gitter](https://gitter.im/OpenIntelWireless/itlwm); once it's confirmed, please use the provided issue template. 24 | 25 | ## Credits 26 | 27 | - [Acidanthera](https://github.com/acidanthera) for [MacKernelSDK](https://github.com/acidanthera/MacKernelSDK) 28 | - [Apple](https://www.apple.com) for [macOS](https://www.apple.com/macos) 29 | - [AppleIntelWiFi](https://github.com/AppleIntelWiFi) for [Black80211-Catalina](https://github.com/AppleIntelWiFi/Black80211-Catalina) 30 | - [ErrorErrorError](https://github.com/ErrorErrorError) for UserClient bug fixes 31 | - [Intel](https://www.intel.com) for [Wireless Adapter Firmwares](https://www.intel.com/content/www/us/en/support/articles/000005511/network-and-io/wireless.html) and [iwlwifi](https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi) 32 | - [Linux](https://www.kernel.org) for [iwlwifi](https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi) 33 | - [mercurysquad](https://github.com/mercurysquad) for [Voodoo80211](https://github.com/mercurysquad/Voodoo80211) 34 | - [OpenBSD](https://openbsd.org) for [net80211, iwn, iwm, and iwx](https://github.com/openbsd/src) 35 | - [pigworlds](https://github.com/OpenIntelWireless/itlwm/commits?author=pigworlds) for DVM devices support, MIRA bug fixes, and Tx aggregation for MVM Gen 1 devices 36 | - [rpeshkov](https://github.com/rpeshkov) for [black80211](https://github.com/rpeshkov/black80211) 37 | - [usr-sse2](https://github.com/usr-sse2) for implementing the usage of Apple RSN Supplicant and bug fixes 38 | - [zxystd](https://github.com/zxystd) for developing [itlwm](https://github.com/OpenIntelWireless/itlwm) 39 | 40 | ## Acknowledgements 41 | 42 | - [@penghubingzhou](https://github.com/startpenghubingzhou) 43 | - [@Bat.bat](https://github.com/williambj1) 44 | - [@iStarForever](https://github.com/XStar-Dev) 45 | - [@stevezhengshiqi](https://github.com/stevezhengshiqi) 46 | - [@DogAndPot](https://github.com/DogAndPot) for providing resources and help for system configuration 47 | - [@Daliansky](https://github.com/Daliansky) for providing Wi-Fi cards 48 | -------------------------------------------------------------------------------- /include/Airport/Apple80211.h: -------------------------------------------------------------------------------- 1 | // 2 | // Apple80211.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/9/4. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef Apple80211_h 10 | #define Apple80211_h 11 | 12 | #include "apple_private_spi.h" 13 | #include "debug.h" 14 | #include "IO80211WorkLoop.h" 15 | #ifdef IO80211FAMILY_V2 16 | #include "IO80211WorkQueue.h" 17 | #include "IO80211ControllerV2.h" 18 | #include "IO80211InfraInterface.h" 19 | #include "IO80211InfraProtocol.h" 20 | #include "IOSkywalkPacketBufferPool.h" 21 | #include "IOSkywalkLegacyEthernetInterface.h" 22 | #include "IO80211SkywalkInterface.h" 23 | #else 24 | #include "IO80211Controller.h" 25 | #include "IO80211Interface.h" 26 | #include "IO80211VirtualInterface.h" 27 | #include "IO80211P2PInterface.h" 28 | #endif /* IO80211FAMILY_V2 */ 29 | 30 | #endif /* Apple80211_h */ 31 | -------------------------------------------------------------------------------- /include/Airport/CCDataPipe.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCDataPipe.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/14. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef CCDataPipe_h 10 | #define CCDataPipe_h 11 | 12 | #include "CCPipe.h" 13 | #include 14 | 15 | class CCDataPipeBlob; 16 | 17 | class CCDataPipe : public CCPipe { 18 | OSDeclareDefaultStructors(CCDataPipe) 19 | 20 | public: 21 | virtual void free() APPLE_KEXT_OVERRIDE; 22 | virtual IOReturn configureReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 23 | virtual IOReturn updateReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 24 | virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE; 25 | virtual void stop( IOService * provider ) APPLE_KEXT_OVERRIDE; 26 | virtual void detach( IOService * provider ) APPLE_KEXT_OVERRIDE; 27 | virtual IOReturn newUserClient( task_t owningTask, void * securityID, 28 | UInt32 type, OSDictionary * properties, 29 | LIBKERN_RETURNS_RETAINED IOUserClient ** handler ) APPLE_KEXT_OVERRIDE; 30 | virtual bool clientClose(void) APPLE_KEXT_OVERRIDE; 31 | virtual void *getCoreCapturePipeReporter(void) APPLE_KEXT_OVERRIDE; 32 | virtual bool isClientConnected(void) APPLE_KEXT_OVERRIDE; 33 | virtual bool startPipe(void) APPLE_KEXT_OVERRIDE; 34 | virtual void stopPipe(void) APPLE_KEXT_OVERRIDE; 35 | virtual UInt generateStreamId(void) APPLE_KEXT_OVERRIDE; 36 | virtual bool addInitCapture(void) APPLE_KEXT_OVERRIDE; 37 | virtual void removeInitCapture(void) APPLE_KEXT_OVERRIDE; 38 | virtual void removeCapture(void) APPLE_KEXT_OVERRIDE; 39 | virtual bool profileLoaded(void) APPLE_KEXT_OVERRIDE; 40 | virtual bool profileRemoved(void) APPLE_KEXT_OVERRIDE; 41 | virtual bool capture(CCTimestamp *,char const*) APPLE_KEXT_OVERRIDE; 42 | virtual bool capture(CCTimestamp,char const*) APPLE_KEXT_OVERRIDE; 43 | virtual bool hasPrivilege(void) APPLE_KEXT_OVERRIDE; 44 | virtual bool hasPrivilegeAdministrator(task_t) APPLE_KEXT_OVERRIDE; 45 | virtual bool initWithOwnerNameCapacity(IOService *,char const*,char const*,CCPipeOptions const*) APPLE_KEXT_OVERRIDE; 46 | virtual OSString *getClassName(void) APPLE_KEXT_OVERRIDE; 47 | virtual void setCCaptureInRegistry(void) APPLE_KEXT_OVERRIDE; 48 | virtual unsigned long getPipeSize(void) APPLE_KEXT_OVERRIDE; 49 | virtual void setPipeSize(unsigned long) APPLE_KEXT_OVERRIDE; 50 | virtual void freeCCCaptureObject(void) APPLE_KEXT_OVERRIDE; 51 | virtual void *getPipeCallbacks(void) APPLE_KEXT_OVERRIDE; 52 | virtual IOService *getProvider(void) APPLE_KEXT_OVERRIDE; 53 | virtual void *getCurrentOptions(void) APPLE_KEXT_OVERRIDE; 54 | virtual void *getDriverOptions(void) APPLE_KEXT_OVERRIDE; 55 | virtual UInt getLoggingFlags(void) APPLE_KEXT_OVERRIDE; 56 | virtual unsigned long getRingEntryMaxTimeMs(void) APPLE_KEXT_OVERRIDE; 57 | virtual unsigned long getRingEntrySleepTimeMs(void) APPLE_KEXT_OVERRIDE; 58 | virtual CCPipeStatistics *getStatistics(void) APPLE_KEXT_OVERRIDE; 59 | virtual void setStatistics(CCPipeStatistics *) APPLE_KEXT_OVERRIDE; 60 | virtual void publishStatistics(void) APPLE_KEXT_OVERRIDE; 61 | virtual void updateStatistics(bool) APPLE_KEXT_OVERRIDE; 62 | virtual IOReturn configureAllReports(void) APPLE_KEXT_OVERRIDE; 63 | virtual IOReturn updateAllReports(void) APPLE_KEXT_OVERRIDE; 64 | virtual void *createReportSet(void) APPLE_KEXT_OVERRIDE; 65 | virtual IOReturn enqueueBlob(CCDataPipeBlob *); 66 | virtual bool dequeueBlob(CCDataPipeBlob **); 67 | virtual void freeResources(void); 68 | virtual void notifyTimeout(IOTimerEventSource *); 69 | 70 | public: 71 | uint8_t filter[0x98]; 72 | }; 73 | 74 | #endif /* CCDataPipe_h */ 75 | -------------------------------------------------------------------------------- /include/Airport/CCLogStream.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCLogStream.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/14. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef CCLogStream_h 10 | #define CCLogStream_h 11 | 12 | #include 13 | #include "CCStream.h" 14 | 15 | enum CCStreamLogLevel 16 | { 17 | LEVEL_1, 18 | }; 19 | 20 | class CCLogStream : public CCStream { 21 | OSDeclareDefaultStructors(CCLogStream) 22 | 23 | public: 24 | virtual void free() APPLE_KEXT_OVERRIDE; 25 | virtual bool init(OSDictionary *) APPLE_KEXT_OVERRIDE; 26 | virtual IOReturn configureReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 27 | virtual IOReturn updateReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 28 | virtual bool start(IOService *) APPLE_KEXT_OVERRIDE; 29 | virtual void stop(IOService *) APPLE_KEXT_OVERRIDE; 30 | virtual bool attach( IOService * provider ) APPLE_KEXT_OVERRIDE; 31 | virtual void detach( IOService * provider ) APPLE_KEXT_OVERRIDE; 32 | virtual bool profileLoaded(void) APPLE_KEXT_OVERRIDE; 33 | virtual bool profileRemoved(void) APPLE_KEXT_OVERRIDE; 34 | virtual CCLogStream const *initWithPipeAndName(CCPipe *,char const*,CCStreamOptions const*) APPLE_KEXT_OVERRIDE; 35 | virtual void setLevel(CCStreamLogLevel); 36 | virtual CCStreamLogLevel getLevel(void); 37 | virtual void setFlags(unsigned long long); 38 | virtual unsigned long long getFlags(void); 39 | virtual void setLogFlag(unsigned long long); 40 | virtual void clearLogFlag(unsigned long long); 41 | virtual void setConsoleLevel(CCStreamLogLevel); 42 | virtual void setConsoleFlags(unsigned long long); 43 | virtual unsigned long long getConsoleFlags(void); 44 | virtual void setConsoleLogFlag(unsigned long long); 45 | virtual void clearConsoleLogFlag(unsigned long long); 46 | 47 | public: 48 | uint8_t filter[0x98]; 49 | }; 50 | 51 | #endif /* CCLogStream_h */ 52 | 53 | -------------------------------------------------------------------------------- /include/Airport/CCPipe.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCPipe.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/14. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef CCPipe_h 10 | #define CCPipe_h 11 | 12 | #include 13 | 14 | class CCTimestamp; 15 | class CCPipeStatistics; 16 | struct CCPipeOptions { 17 | uint64_t pipe_type; // 0x0 18 | uint64_t log_data_type; // 0x8 19 | uint64_t pipe_size; // 0x10 20 | uint64_t min_log_size_notify; // 0x18 21 | uint32_t notify_threshold; // 0x20 22 | char file_name[0x100]; // 0x24 23 | char name[0xF0]; // 0x124 24 | char pad8[0x10]; // 0x214 25 | uint32_t pad9; // 0x224 26 | uint32_t pad10; // 0x228 27 | uint64_t file_options; // 0x230 28 | uint64_t log_policy; // 0x238 29 | uint32_t pad13; 30 | char directory_name[0x100]; // 0x244 31 | uint8_t pad[0xC]; 32 | }; 33 | 34 | static_assert(offsetof(CCPipeOptions, pipe_size) == 0x10, "Invalid offset"); 35 | static_assert(offsetof(CCPipeOptions, file_name) == 0x24, "Invalid offset"); 36 | static_assert(offsetof(CCPipeOptions, name) == 0x124, "Invalid offset"); 37 | static_assert(offsetof(CCPipeOptions, pad9) == 0x224, "Invalid offset"); 38 | static_assert(offsetof(CCPipeOptions, pad10) == 0x228, "Invalid offset"); 39 | static_assert(offsetof(CCPipeOptions, file_options) == 0x230, "Invalid offset"); 40 | static_assert(offsetof(CCPipeOptions, log_policy) == 0x238, "Invalid offset"); 41 | static_assert(offsetof(CCPipeOptions, directory_name) == 0x244, "Invalid offset"); 42 | static_assert(sizeof(CCPipeOptions) == 0x350, "Invalid offset"); 43 | 44 | 45 | class CCPipe : public IOService { 46 | OSDeclareAbstractStructors(CCPipe) 47 | 48 | public: 49 | virtual void free() APPLE_KEXT_OVERRIDE; 50 | virtual IOReturn configureReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 51 | virtual IOReturn updateReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 52 | virtual void detach( IOService * provider ) APPLE_KEXT_OVERRIDE; 53 | virtual IOReturn newUserClient( task_t owningTask, void * securityID, 54 | UInt32 type, OSDictionary * properties, 55 | LIBKERN_RETURNS_RETAINED IOUserClient ** handler ) = 0; 56 | virtual bool clientClose(void) = 0; 57 | virtual void *getCoreCapturePipeReporter(void); 58 | virtual bool isClientConnected(void) = 0; 59 | virtual bool startPipe(void); 60 | virtual void stopPipe(void); 61 | virtual UInt generateStreamId(void); 62 | virtual bool addInitCapture(void); 63 | virtual void removeInitCapture(void); 64 | virtual void removeCapture(void); 65 | virtual bool profileLoaded(void); 66 | virtual bool profileRemoved(void); 67 | virtual bool capture(CCTimestamp *,char const*) = 0; 68 | virtual bool capture(CCTimestamp,char const*) = 0; 69 | virtual bool hasPrivilege(void); 70 | virtual bool hasPrivilegeAdministrator(task_t); 71 | virtual bool initWithOwnerNameCapacity(IOService *,char const*,char const*,CCPipeOptions const*); 72 | virtual OSString *getClassName(void); 73 | virtual void setCCaptureInRegistry(void); 74 | virtual unsigned long getPipeSize(void); 75 | virtual void setPipeSize(unsigned long); 76 | virtual void freeCCCaptureObject(void); 77 | virtual void *getPipeCallbacks(void); 78 | virtual IOService *getProvider(void); 79 | virtual void *getCurrentOptions(void); 80 | virtual void *getDriverOptions(void); 81 | virtual UInt getLoggingFlags(void); 82 | virtual unsigned long getRingEntryMaxTimeMs(void); 83 | virtual unsigned long getRingEntrySleepTimeMs(void); 84 | virtual CCPipeStatistics *getStatistics(void); 85 | virtual void setStatistics(CCPipeStatistics *); 86 | virtual void publishStatistics(void); 87 | virtual void updateStatistics(bool); 88 | virtual IOReturn configureAllReports(void); 89 | virtual IOReturn updateAllReports(void); 90 | virtual void *createReportSet(void); 91 | 92 | public: 93 | static CCPipe *withOwnerNameCapacity(IOService *,char const*,char const*,CCPipeOptions const*); 94 | 95 | public: 96 | uint8_t filter[0x90]; 97 | }; 98 | 99 | #endif /* CCPipe_h */ 100 | -------------------------------------------------------------------------------- /include/Airport/CCStream.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCStream.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/14. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef CCStream_h 10 | #define CCStream_h 11 | 12 | #include 13 | #include "CCPipe.h" 14 | 15 | struct CCStreamOptions { 16 | uint64_t stream_type; 17 | uint64_t console_level; 18 | char pad[0x348]; 19 | }; 20 | 21 | class CCStream : public IOService { 22 | OSDeclareAbstractStructors(CCStream) 23 | 24 | public: 25 | virtual void free() APPLE_KEXT_OVERRIDE; 26 | virtual IOReturn configureReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 27 | virtual IOReturn updateReport(IOReportChannelList *,UInt,void *,void *) APPLE_KEXT_OVERRIDE; 28 | virtual bool attach( IOService * provider ) APPLE_KEXT_OVERRIDE; 29 | virtual void detach( IOService * provider ) APPLE_KEXT_OVERRIDE; 30 | virtual bool profileLoaded(void); 31 | virtual bool profileRemoved(void); 32 | virtual CCStream const *initWithPipeAndName(CCPipe *,char const*,CCStreamOptions const*); 33 | 34 | public: 35 | static CCStream *withPipeAndName(CCPipe *,char const*,CCStreamOptions const*); 36 | CCPipe *getPipe() const; 37 | 38 | public: 39 | uint8_t filter[0x90]; 40 | }; 41 | 42 | #endif /* CCStream_h */ 43 | 44 | -------------------------------------------------------------------------------- /include/Airport/IO80211WorkLoop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IO80211WorkLoop.h 3 | * IO80211Family 4 | * 5 | * Created by Pete on 5/31/06. 6 | * Copyright 2006 Apple Computer, Inc. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef _IO80211WORKLOOP_H 11 | #define _IO80211WORKLOOP_H 12 | 13 | #include 14 | #include 15 | 16 | // This is necessary, because even the latest Xcode does not support properly targeting 11.0. 17 | #ifndef __IO80211_TARGET 18 | #error "Please define __IO80211_TARGET to the requested version" 19 | #endif 20 | 21 | class IO80211WorkLoop : public IOWorkLoop 22 | { 23 | OSDeclareDefaultStructors( IO80211WorkLoop ) 24 | 25 | public: 26 | 27 | static IO80211WorkLoop * workLoop(); 28 | 29 | virtual void openGate() APPLE_KEXT_OVERRIDE; 30 | virtual void closeGate() APPLE_KEXT_OVERRIDE; 31 | virtual int sleepGate( void * event, UInt32 interuptibleType ) APPLE_KEXT_OVERRIDE; 32 | virtual int sleepGateDeadline( void * event, UInt32 interuptibleType, AbsoluteTime deadline ); 33 | virtual void wakeupGate( void * event, bool oneThread ) APPLE_KEXT_OVERRIDE; 34 | 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/Airport/IO80211WorkQueue.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _IO80211WORKQUEUE_H 3 | #define _IO80211WORKQUEUE_H 4 | 5 | #include 6 | #include 7 | 8 | // This is necessary, because even the latest Xcode does not support properly targeting 11.0. 9 | #ifndef __IO80211_TARGET 10 | #error "Please define __IO80211_TARGET to the requested version" 11 | #endif 12 | 13 | class IO80211WorkQueue : public IOWorkLoop 14 | { 15 | OSDeclareDefaultStructors( IO80211WorkQueue ) 16 | 17 | public: 18 | 19 | virtual IOThread getThread() const APPLE_KEXT_OVERRIDE; 20 | virtual void enableAllInterrupts() const APPLE_KEXT_OVERRIDE; 21 | virtual void disableAllInterrupts() const APPLE_KEXT_OVERRIDE; 22 | virtual IOReturn runAction(Action action, OSObject *target, 23 | void *arg0 = NULL, void *arg1 = NULL, 24 | void *arg2 = NULL, void *arg3 = NULL) APPLE_KEXT_OVERRIDE; 25 | virtual int commandSleep(void *,unsigned long long); 26 | virtual void commandWakeup(void *); 27 | 28 | static IO80211WorkQueue * workQueue(); 29 | 30 | public: 31 | uint8_t filter[0x50]; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkEthernetInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef IOSkywalkEthernetInterface_h 2 | #define IOSkywalkEthernetInterface_h 3 | 4 | #include "IOSkywalkNetworkInterface.h" 5 | 6 | struct nicproxy_limits_info_s; 7 | struct nicproxy_info_s; 8 | 9 | class IOSkywalkEthernetInterface : public IOSkywalkNetworkInterface { 10 | OSDeclareAbstractStructors( IOSkywalkEthernetInterface ) 11 | 12 | public: 13 | struct RegistrationInfo { 14 | uint8_t pad[304]; 15 | } __attribute__((packed)); 16 | 17 | public: 18 | virtual void free() APPLE_KEXT_OVERRIDE; 19 | virtual bool init(OSDictionary *) APPLE_KEXT_OVERRIDE; 20 | virtual IOReturn newUserClient( task_t owningTask, void * securityID, 21 | UInt32 type, OSDictionary * properties, 22 | LIBKERN_RETURNS_RETAINED IOUserClient ** handler ) APPLE_KEXT_OVERRIDE; 23 | virtual IOReturn setPowerState( 24 | unsigned long powerStateOrdinal, 25 | IOService * whatDevice ) APPLE_KEXT_OVERRIDE; 26 | virtual IOReturn enable(UInt) APPLE_KEXT_OVERRIDE; 27 | virtual SInt32 initBSDInterfaceParameters(ifnet_init_eparams *,sockaddr_dl **) APPLE_KEXT_OVERRIDE; 28 | virtual bool prepareBSDInterface(ifnet_t,UInt) APPLE_KEXT_OVERRIDE; 29 | virtual IOReturn processBSDCommand(ifnet_t,UInt,void *) APPLE_KEXT_OVERRIDE; 30 | virtual void *getPacketTapInfo(UInt *,UInt *) APPLE_KEXT_OVERRIDE; 31 | virtual void enableNetworkWake(UInt) APPLE_KEXT_OVERRIDE; 32 | virtual UInt getMaxTransferUnit(void) APPLE_KEXT_OVERRIDE; 33 | virtual UInt getMinPacketSize(void) APPLE_KEXT_OVERRIDE; 34 | virtual void *getInterfaceFamily(void) APPLE_KEXT_OVERRIDE; 35 | virtual void *getInterfaceSubFamily(void) APPLE_KEXT_OVERRIDE; 36 | virtual UInt getInitialMedia(void) APPLE_KEXT_OVERRIDE; 37 | virtual const char *getBSDNamePrefix(void) APPLE_KEXT_OVERRIDE; 38 | virtual IOReturn registerNetworkInterfaceWithLogicalLink(IOSkywalkEthernetInterface::RegistrationInfo const*, IOSkywalkLogicalLink*, IOSkywalkPacketBufferPool*, IOSkywalkPacketBufferPool*, UInt); 39 | virtual void getHardwareAddress(ether_addr *); 40 | virtual void setHardwareAddress(ether_addr *); 41 | virtual void setLinkLayerAddress(ether_addr *); 42 | virtual bool configureMulticastFilter(UInt,ether_addr const*,UInt); 43 | virtual bool setMulticastAddresses(ether_addr const*,UInt); 44 | virtual void setAllMulticastModeEnable(bool); 45 | virtual IOReturn setPromiscuousModeEnable(bool, UInt); 46 | virtual void reportNicProxyLimits(nicproxy_limits_info_s); 47 | virtual void hwConfigNicProxyData(nicproxy_info_s *); 48 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 0 ); 49 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 1 ); 50 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 2 ); 51 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 3 ); 52 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 4 ); 53 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 5 ); 54 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 6 ); 55 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 7 ); 56 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 8 ); 57 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 9 ); 58 | OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 10 ); 59 | 60 | public: 61 | bool initRegistrationInfo(IOSkywalkEthernetInterface::RegistrationInfo*, unsigned int, unsigned long); 62 | bool registerEthernetInterface(IOSkywalkEthernetInterface::RegistrationInfo const*, IOSkywalkPacketQueue**, unsigned int, IOSkywalkPacketBufferPool*, IOSkywalkPacketBufferPool*, unsigned int); 63 | 64 | public: 65 | void *vptr; 66 | uint8_t pad1[0x30]; 67 | struct ExpansionData 68 | { 69 | RegistrationInfo *fRegistrationInfo; 70 | ifnet_t fBSDInterface; 71 | }; 72 | ExpansionData *mExpansionData2; 73 | }; 74 | 75 | static_assert(__offsetof(IOSkywalkEthernetInterface, mExpansionData2) == 0x108, "Invalid class size"); 76 | 77 | static_assert(sizeof(IOSkywalkEthernetInterface) == 0x110, "Invalid class size"); 78 | 79 | #endif /* IOSkywalkEthernetInterface_h */ 80 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkInterface.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkInterface.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/7. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkInterface_h 10 | #define IOSkywalkInterface_h 11 | 12 | 13 | class IOSkywalkInterface : public IOService { 14 | OSDeclareAbstractStructors(IOSkywalkInterface) 15 | 16 | public: 17 | virtual void free() APPLE_KEXT_OVERRIDE; 18 | virtual bool init(OSDictionary *) APPLE_KEXT_OVERRIDE; 19 | virtual bool willTerminate( IOService * provider, IOOptionBits options ) APPLE_KEXT_OVERRIDE; 20 | virtual bool didTerminate( IOService * provider, IOOptionBits options, bool * defer ) APPLE_KEXT_OVERRIDE; 21 | virtual bool handleOpen( IOService * forClient, 22 | IOOptionBits options, 23 | void * arg ) APPLE_KEXT_OVERRIDE; 24 | virtual void handleClose( IOService * forClient, 25 | IOOptionBits options ) APPLE_KEXT_OVERRIDE; 26 | virtual bool handleIsOpen( const IOService * forClient ) const APPLE_KEXT_OVERRIDE; 27 | virtual IOReturn enable( IOOptionBits options ) = 0; 28 | virtual IOReturn disable( IOOptionBits options ) = 0; 29 | virtual IOReturn clientConnectWithTask( task_t task, IOService * forClient, IOOptionBits options ); 30 | virtual void clientDisconnect( IOService * forClient, IOOptionBits options ); 31 | virtual bool isTerminating(void); 32 | 33 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 0 ); 34 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 1 ); 35 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 2 ); 36 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 3 ); 37 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 4 ); 38 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 5 ); 39 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 6 ); 40 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 7 ); 41 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 8 ); 42 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 9 ); 43 | OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 10 ); 44 | 45 | public: 46 | uint8_t filter[0xB0 - 136]; 47 | }; 48 | 49 | static_assert(sizeof(IOSkywalkInterface) == 0xB0, "Invalid class size"); 50 | 51 | #endif /* IOSkywalkInterface_h */ 52 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkLegacyEthernetInterface.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkLegacyEthernetInterface.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/19. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkLegacyEthernetInterface_h 10 | #define IOSkywalkLegacyEthernetInterface_h 11 | 12 | #include 13 | #include 14 | 15 | class IOSkywalkLegacyEthernetInterface : public IOEthernetInterface { 16 | OSDeclareDefaultStructors(IOSkywalkLegacyEthernetInterface) 17 | 18 | public: 19 | virtual void free() APPLE_KEXT_OVERRIDE; 20 | virtual OSObject * getProperty( const OSSymbol * aKey) const APPLE_KEXT_OVERRIDE; 21 | virtual OSObject * copyProperty( const OSSymbol * aKey) const APPLE_KEXT_OVERRIDE; 22 | virtual bool serializeProperties( OSSerialize * serialize ) const APPLE_KEXT_OVERRIDE; 23 | virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE; 24 | virtual bool init( IONetworkController * controller ) APPLE_KEXT_OVERRIDE; 25 | virtual const char * getNamePrefix() const APPLE_KEXT_OVERRIDE; 26 | virtual bool controllerDidOpen(IONetworkController * controller) APPLE_KEXT_OVERRIDE; 27 | virtual void controllerWillClose(IONetworkController * controller) APPLE_KEXT_OVERRIDE; 28 | virtual ifnet_t getIfnet( void ) const APPLE_KEXT_OVERRIDE; 29 | virtual IOReturn attachToDataLinkLayer( IOOptionBits options, void * parameter ) APPLE_KEXT_OVERRIDE; 30 | virtual void detachFromDataLinkLayer( IOOptionBits options, 31 | void * parameter ) APPLE_KEXT_OVERRIDE; 32 | 33 | public: 34 | uint8_t filter[0x160]; 35 | }; 36 | 37 | #endif /* IOSkywalkLegacyEthernetInterface_h */ 38 | 39 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkLogicalLink.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkLogicalLink.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/12. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkLogicalLink_h 10 | #define IOSkywalkLogicalLink_h 11 | 12 | class IOSkywalkLogicalLink : public IOService { 13 | OSDeclareAbstractStructors(IOSkywalkLogicalLink) 14 | 15 | public: 16 | 17 | public: 18 | }; 19 | 20 | #endif /* IOSkywalkLogicalLink_h */ 21 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkNetworkInterface.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkNetworkInterface.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/7. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkNetworkInterface_h 10 | #define IOSkywalkNetworkInterface_h 11 | 12 | #include 13 | 14 | #include "IOSkywalkInterface.h" 15 | 16 | typedef UInt if_link_status; 17 | class IOSkywalkPacketQueue; 18 | class IOSkywalkLogicalLink; 19 | class IOSkywalkPacketBufferPool; 20 | 21 | class IOSkywalkNetworkInterface : public IOSkywalkInterface { 22 | OSDeclareAbstractStructors( IOSkywalkNetworkInterface ) 23 | 24 | public: 25 | struct RegistrationInfo { 26 | uint8_t pad[304]; 27 | } __attribute__((packed)); 28 | struct IOSkywalkTSOOptions; 29 | 30 | public: 31 | virtual void free() APPLE_KEXT_OVERRIDE; 32 | virtual bool init(OSDictionary *) APPLE_KEXT_OVERRIDE; 33 | virtual void stop(IOService *) APPLE_KEXT_OVERRIDE; 34 | virtual void joinPMtree( IOService * driver ) APPLE_KEXT_OVERRIDE; 35 | virtual IOReturn setAggressiveness( 36 | unsigned long type, 37 | unsigned long newLevel ) APPLE_KEXT_OVERRIDE; 38 | virtual IOReturn enable(UInt) APPLE_KEXT_OVERRIDE; 39 | virtual IOReturn disable(UInt) APPLE_KEXT_OVERRIDE; 40 | virtual SInt32 initBSDInterfaceParameters(ifnet_init_eparams *,sockaddr_dl **) = 0; 41 | virtual bool prepareBSDInterface(ifnet_t,UInt); 42 | virtual void finalizeBSDInterface(ifnet_t,UInt); 43 | virtual ifnet_t getBSDInterface(void); 44 | virtual void setBSDName(char const*); 45 | virtual const char *getBSDName(void); 46 | virtual IOReturn processBSDCommand(ifnet_t,UInt,void *); 47 | virtual IOReturn processInterfaceCommand(ifdrv *); 48 | virtual IOReturn interfaceAdvisoryEnable(bool); 49 | virtual SInt32 setInterfaceEnable(bool); 50 | virtual SInt32 setRunningState(bool); 51 | virtual IOReturn handleChosenMedia(UInt); 52 | virtual void *getSupportedMediaArray(UInt *,UInt *); 53 | virtual void *getPacketTapInfo(UInt *,UInt *); 54 | virtual UInt getUnsentDataByteCount(UInt *,UInt *,UInt); 55 | virtual UInt32 getSupportedWakeFlags(UInt *); 56 | virtual void enableNetworkWake(UInt); 57 | virtual void calculateRingSizeForQueue(IOSkywalkPacketQueue const*,UInt *); 58 | virtual UInt getMaxTransferUnit(void); 59 | virtual void setMaxTransferUnit(UInt); 60 | virtual UInt getMinPacketSize(void); 61 | virtual UInt getHardwareAssists(void); 62 | virtual void setHardwareAssists(UInt,UInt); 63 | virtual void *getInterfaceFamily(void); 64 | virtual void *getInterfaceSubFamily(void); 65 | virtual UInt getInitialMedia(void); 66 | virtual UInt getFeatureFlags(void); 67 | virtual UInt getTxDataOffset(void); 68 | virtual UInt captureInterfaceState(UInt); 69 | virtual void restoreInterfaceState(UInt); 70 | virtual void setMTU(UInt); 71 | virtual bool bpfTap(UInt,UInt); 72 | virtual const char *getBSDNamePrefix(void); 73 | virtual UInt getBSDUnitNumber(void); 74 | virtual const char *classNameOverride(void); 75 | virtual void deferBSDAttach(bool); 76 | virtual void reportDetailedLinkStatus(if_link_status const*); 77 | virtual IOReturn registerNetworkInterfaceWithLogicalLink(IOSkywalkNetworkInterface::RegistrationInfo const*,IOSkywalkLogicalLink *,IOSkywalkPacketBufferPool *,IOSkywalkPacketBufferPool *,UInt); 78 | virtual IOReturn deregisterLogicalLink(void); 79 | virtual UInt getTSOOptions(IOSkywalkNetworkInterface::IOSkywalkTSOOptions *); 80 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 0); 81 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 1); 82 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 2); 83 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 3); 84 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 4); 85 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 5); 86 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 6); 87 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 7); 88 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 8); 89 | OSMetaClassDeclareReservedUnused( IOSkywalkNetworkInterface, 9); 90 | 91 | public: 92 | void reportLinkStatus(unsigned int, unsigned int); 93 | 94 | public: 95 | void *vptr; 96 | struct ExpansionData 97 | { 98 | RegistrationInfo *fRegistrationInfo; 99 | ifnet_t fBSDInterface; 100 | }; 101 | ExpansionData *mExpansionData; 102 | uint8_t pad[2 * 8]; 103 | }; 104 | 105 | static_assert(sizeof(IOSkywalkNetworkInterface) == 0xD0, "Invalid class size"); 106 | 107 | #endif /* IOSkywalkNetworkInterface_h */ 108 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkNetworkPacket.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkNetworkPacket.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/13. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkInterface_h 10 | #define IOSkywalkInterface_h 11 | 12 | class IOSkywalkPacketBufferPool; 13 | class IOSkywalkPacketDescriptor; 14 | class IOSkywalkPacketBuffer; 15 | class IOSkywalkPacketQueue; 16 | 17 | class IOSkywalkNetworkPacket : public IOService { 18 | OSDeclareAbstractStructors(IOSkywalkNetworkPacket) 19 | 20 | public: 21 | virtual void free() APPLE_KEXT_OVERRIDE; 22 | 23 | virtual bool initWithPool(IOSkywalkPacketBufferPool *,IOSkywalkPacketDescriptor *,uint); 24 | virtual void *getPacketBuffers(IOSkywalkPacketBuffer **,uint); 25 | virtual UInt getPacketBufferCount(void); 26 | virtual IOSkywalkPacketDescriptor *getMemoryDescriptor(void); 27 | virtual void setDataLength(uint); 28 | virtual UInt getDataLength(void); 29 | virtual void setDataOffset(unsigned short); 30 | virtual unsigned short getDataOffset(void); 31 | virtual void setDataOffsetAndLength(unsigned short,uint); 32 | virtual void setDataOff(long long); 33 | virtual long long getDataOff(void); 34 | virtual void setDataOffAndLen(long long,unsigned long); 35 | virtual void *getDataVirtualAddress(void); 36 | virtual void *getDataIOVirtualAddress(void); 37 | virtual bool prepareWithQueue(IOSkywalkPacketQueue *,uint,uint); 38 | virtual bool prepare(IOSkywalkPacketQueue *,unsigned long long,uint); 39 | virtual void completeWithQueue(IOSkywalkPacketQueue *,uint,uint); 40 | virtual void complete(IOSkywalkPacketQueue *,uint); 41 | virtual UInt getPacketType(void); 42 | virtual void setWakeFlag(void); 43 | virtual UInt getTraceID(void); 44 | virtual void setTraceID(UInt); 45 | virtual void traceEvent(uint); 46 | virtual void *generateTraceTag(IOSkywalkPacketQueue *); 47 | virtual void *acquireWithPacketHandle(unsigned long long,uint); 48 | virtual void disposePacket(void); 49 | 50 | public: 51 | uint8_t filter[0x78]; 52 | }; 53 | 54 | #endif /* IOSkywalkInterface_h */ 55 | -------------------------------------------------------------------------------- /include/Airport/IOSkywalkPacketBufferPool.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSkywalkPacketBufferPool.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2023/6/15. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef IOSkywalkPacketBufferPool_h 10 | #define IOSkywalkPacketBufferPool_h 11 | 12 | #include 13 | 14 | class IOSkywalkMemorySegment; 15 | class IOSkywalkMemorySegmentDescriptor; 16 | class IOSkywalkPacket; 17 | class IOSkywalkPacketBuffer; 18 | class IOSkywalkPacketDescriptor; 19 | class IOSkywalkPacketBufferDescriptor; 20 | 21 | class IOSkywalkPacketBufferPool : public OSObject { 22 | OSDeclareDefaultStructors(IOSkywalkPacketBufferPool) 23 | 24 | public: 25 | struct PoolOptions { 26 | uint32_t packetCount; 27 | uint32_t bufferCount; 28 | uint32_t bufferSize; 29 | uint32_t maxBuffersPerPacket; 30 | uint32_t memorySegmentSize; 31 | uint32_t poolFlags; 32 | uint64_t pad; 33 | }; 34 | 35 | public: 36 | virtual void free() APPLE_KEXT_OVERRIDE; 37 | virtual bool initWithName(char const*,void *,uint,IOSkywalkPacketBufferPool::PoolOptions const*); 38 | virtual bool initWithName(char const*,OSObject *,uint,IOSkywalkPacketBufferPool::PoolOptions const*); 39 | virtual bool allocatePacket(IOSkywalkPacket **,uint); 40 | virtual bool allocatePacket(uint,IOSkywalkPacket **,uint); 41 | virtual bool allocatePackets(uint,uint *,IOSkywalkPacket **,uint); 42 | virtual void deallocatePacket(IOSkywalkPacket *); 43 | virtual void deallocatePackets(IOSkywalkPacket **,uint); 44 | virtual void deallocatePacketList(IOSkywalkPacket *); 45 | virtual void deallocatePacketChain(unsigned long long); 46 | virtual bool allocatePacketBuffer(IOSkywalkPacketBuffer **,uint); 47 | virtual bool allocatePacketBuffers(uint *,IOSkywalkPacketBuffer **,uint); 48 | virtual void deallocatePacketBuffer(IOSkywalkPacketBuffer *); 49 | virtual void deallocatePacketBuffers(IOSkywalkPacketBuffer **,uint); 50 | virtual bool newPacket(IOSkywalkPacketDescriptor *,IOSkywalkPacket **); 51 | virtual bool newPacketBuffer(IOSkywalkPacketBufferDescriptor *,IOSkywalkPacketBuffer **); 52 | virtual bool newMemorySegment(IOSkywalkMemorySegmentDescriptor *,IOSkywalkMemorySegment **); 53 | 54 | public: 55 | static IOSkywalkPacketBufferPool *withName(char const*,OSObject *,uint,IOSkywalkPacketBufferPool::PoolOptions const*); 56 | 57 | public: 58 | uint8_t filter[0xB8]; 59 | }; 60 | 61 | #endif /* IOSkywalkPacketBufferPool_h */ 62 | 63 | -------------------------------------------------------------------------------- /include/Airport/apple_private_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2016 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef apple_private_spi_h 30 | #define apple_private_spi_h 31 | 32 | #ifndef __PRIVATE_SPI__ 33 | 34 | /*! @enum IOMbufServiceClass 35 | @discussion Service class of a mbuf packet. 36 | @constant kIOMbufServiceClassBKSYS Background System-Initiated. 37 | @constant kIOMbufServiceClassBK Background. 38 | @constant kIOMbufServiceClassBE Best Effort. 39 | @constant kIOMbufServiceClassRD Responsive Data. 40 | @constant kIOMbufServiceClassOAM Operations, Administration, and Management. 41 | @constant kIOMbufServiceClassAV Multimedia Audio/Video Streaming. 42 | @constant kIOMbufServiceClassRV Responsive Multimedia Audio/Video. 43 | @constant kIOMbufServiceClassVI Interactive Video. 44 | @constant kIOMbufServiceClassVO Interactive Voice. 45 | @constant kIOMbufServiceClassCTL Network Control. 46 | */ 47 | enum IOMbufServiceClass { 48 | kIOMbufServiceClassBKSYS = 100, 49 | kIOMbufServiceClassBK = 200, 50 | kIOMbufServiceClassBE = 0, 51 | kIOMbufServiceClassRD = 300, 52 | kIOMbufServiceClassOAM = 400, 53 | kIOMbufServiceClassAV = 500, 54 | kIOMbufServiceClassRV = 600, 55 | kIOMbufServiceClassVI = 700, 56 | kIOMbufServiceClassVO = 800, 57 | kIOMbufServiceClassCTL = 900 58 | }; 59 | 60 | #endif 61 | 62 | struct packet_info_tag { 63 | 64 | }; 65 | 66 | struct apple80211_debug_command { 67 | 68 | }; 69 | 70 | struct ifnet_init_eparams { 71 | 72 | }; 73 | 74 | #endif /* apple_private_spi_h */ 75 | -------------------------------------------------------------------------------- /include/ClientKit/IoctlId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef IoctlId_h 16 | #define IoctlId_h 17 | 18 | enum IOCTL_IDS { 19 | IOCTL_80211_DRIVER_INFO, 20 | IOCTL_80211_STA_INFO, 21 | IOCTL_80211_POWER, 22 | IOCTL_80211_STATE, 23 | IOCTL_80211_NW_ID, 24 | IOCTL_80211_WPA_KEY, 25 | IOCTL_80211_ASSOCIATE, 26 | IOCTL_80211_DISASSOCIATE, 27 | IOCTL_80211_JOIN, 28 | IOCTL_80211_SCAN, 29 | IOCTL_80211_SCAN_RESULT, 30 | IOCTL_80211_TX_POWER_LEVEL, 31 | IOCTL_80211_NW_BSSID, 32 | 33 | IOCTL_ID_MAX 34 | }; 35 | 36 | #endif /* IoctlId_h */ 37 | -------------------------------------------------------------------------------- /include/FwData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef FwData_h 16 | #define FwData_h 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | struct FwDesc { 24 | const char *name; 25 | const unsigned char *var; 26 | const int size; 27 | }; 28 | 29 | #define IWL_FW(fw_name, fw_var, fw_size) \ 30 | .name = fw_name, .var = fw_var, .size = fw_size 31 | 32 | 33 | extern const struct FwDesc fwList[]; 34 | extern const int fwNumber; 35 | 36 | static inline OSData *getFWDescByName(const char* name) { 37 | for (int i = 0; i < fwNumber; i++) { 38 | if (strcmp(fwList[i].name, name) == 0) { 39 | FwDesc desc = fwList[i]; 40 | return OSData::withBytes(desc.var, desc.size); 41 | } 42 | } 43 | return NULL; 44 | } 45 | 46 | static inline bool uncompressFirmware(unsigned char *dest, uint *destLen, unsigned char *source, uint sourceLen) 47 | { 48 | z_stream stream; 49 | int err; 50 | 51 | stream.next_in = source; 52 | stream.avail_in = sourceLen; 53 | stream.next_out = dest; 54 | stream.avail_out = *destLen; 55 | stream.zalloc = zcalloc; 56 | stream.zfree = zcfree; 57 | err = inflateInit(&stream); 58 | if (err != Z_OK) { 59 | return false; 60 | } 61 | err = inflate(&stream, Z_FINISH); 62 | if (err != Z_STREAM_END) { 63 | inflateEnd(&stream); 64 | return false; 65 | } 66 | *destLen = (uint)stream.total_out; 67 | 68 | err = inflateEnd(&stream); 69 | return err == Z_OK; 70 | } 71 | 72 | #endif /* FwData_h */ 73 | -------------------------------------------------------------------------------- /include/HAL/ItlDriverController.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef ItlDriverController_h 16 | #define ItlDriverController_h 17 | 18 | class ItlDriverController { 19 | 20 | public: 21 | 22 | virtual void clearScanningFlags() = 0; 23 | 24 | virtual IOReturn setMulticastList(IOEthernetAddress *addr, int count) = 0; 25 | }; 26 | 27 | #endif /* ItlDriverController_h */ 28 | -------------------------------------------------------------------------------- /include/HAL/ItlDriverInfo.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef ItlDriverInfo_h 16 | #define ItlDriverInfo_h 17 | 18 | class ItlDriverInfo { 19 | 20 | public: 21 | 22 | virtual const char *getFirmwareVersion() = 0; 23 | 24 | virtual int16_t getBSSNoise() = 0; 25 | 26 | virtual bool is5GBandSupport() = 0; 27 | 28 | virtual int getTxNSS() = 0; 29 | 30 | virtual const char *getFirmwareName() = 0; 31 | 32 | virtual UInt32 supportedFeatures() = 0; 33 | 34 | virtual const char *getFirmwareCountryCode() = 0; 35 | 36 | virtual uint32_t getTxQueueSize() = 0; 37 | }; 38 | 39 | #endif /* ItlDriverInfo_h */ 40 | -------------------------------------------------------------------------------- /include/HAL/ItlHalService.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #include "ItlHalService.hpp" 16 | 17 | #define super OSObject 18 | OSDefineMetaClassAndAbstractStructors(ItlHalService, OSObject) 19 | 20 | bool ItlHalService:: 21 | initWithController(IOEthernetController *controller, IOWorkLoop *workloop, IOCommandGate *commandGate) 22 | { 23 | this->controller = controller; 24 | this->controller->retain(); 25 | this->mainWorkLoop = workloop; 26 | this->mainWorkLoop->retain(); 27 | this->mainCommandGate = commandGate; 28 | this->mainCommandGate->retain(); 29 | this->inner_attr = lck_attr_alloc_init(); 30 | this->inner_gp_attr = lck_grp_attr_alloc_init(); 31 | this->inner_gp = lck_grp_alloc_init("itlwm_tsleep", this->inner_gp_attr); 32 | this->inner_lock = lck_mtx_alloc_init(this->inner_gp, this->inner_attr); 33 | return true; 34 | } 35 | 36 | IOEthernetController *ItlHalService:: 37 | getController() 38 | { 39 | return this->controller; 40 | } 41 | 42 | IOCommandGate *ItlHalService:: 43 | getMainCommandGate() 44 | { 45 | return this->mainCommandGate; 46 | } 47 | 48 | IOWorkLoop *ItlHalService:: 49 | getMainWorkLoop() 50 | { 51 | return this->mainWorkLoop; 52 | } 53 | 54 | void ItlHalService:: 55 | wakeupOn(void *ident) 56 | { 57 | // XYLog("%s\n", __FUNCTION__); 58 | wakeup(ident); 59 | } 60 | 61 | int ItlHalService:: 62 | tsleep_nsec(void *ident, int priority, const char *wmesg, int timo) 63 | { 64 | // XYLog("%s %s\n", __FUNCTION__, wmesg); 65 | struct timespec ts; 66 | int err; 67 | memset(&ts, 0, sizeof(struct timespec)); 68 | ts.tv_nsec = timo; 69 | lck_mtx_lock(this->inner_lock); 70 | err = msleep(ident, this->inner_lock, priority, wmesg, &ts); 71 | lck_mtx_unlock(this->inner_lock); 72 | return err; 73 | } 74 | 75 | void ItlHalService:: 76 | free() 77 | { 78 | XYLog("%s\n", __PRETTY_FUNCTION__); 79 | if (this->mainWorkLoop) { 80 | this->mainWorkLoop->release(); 81 | } 82 | this->mainWorkLoop = NULL; 83 | if (this->mainCommandGate) { 84 | this->mainCommandGate->release(); 85 | } 86 | this->mainCommandGate = NULL; 87 | if (this->controller) { 88 | this->controller->release(); 89 | } 90 | if (this->inner_lock) { 91 | lck_attr_free(this->inner_attr); 92 | lck_mtx_free(this->inner_lock, this->inner_gp); 93 | lck_grp_free(this->inner_gp); 94 | lck_grp_attr_free(this->inner_gp_attr); 95 | this->inner_lock = NULL; 96 | } 97 | this->controller = NULL; 98 | super::free(); 99 | } 100 | -------------------------------------------------------------------------------- /include/HAL/ItlHalService.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef ItlHalService_hpp 16 | #define ItlHalService_hpp 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "ItlDriverInfo.hpp" 28 | #include "ItlDriverController.hpp" 29 | 30 | #include 31 | 32 | class ItlHalService : public OSObject { 33 | OSDeclareAbstractStructors(ItlHalService) 34 | 35 | public: 36 | 37 | virtual bool attach(IOPCIDevice *device) = 0; 38 | 39 | virtual void detach(IOPCIDevice *device) = 0; 40 | 41 | virtual IOReturn enable(IONetworkInterface *interface) = 0; 42 | 43 | virtual IOReturn disable(IONetworkInterface *interface) = 0; 44 | 45 | virtual struct ieee80211com *get80211Controller() = 0; 46 | 47 | virtual ItlDriverInfo *getDriverInfo() = 0; 48 | 49 | virtual ItlDriverController *getDriverController() = 0; 50 | 51 | virtual void free() override; 52 | 53 | public: 54 | virtual bool initWithController(IOEthernetController *controller, IOWorkLoop *workloop, IOCommandGate *commandGate); 55 | 56 | protected: 57 | 58 | int tsleep_nsec(void *ident, int priority, const char *wmesg, int timo); 59 | 60 | void wakeupOn(void* ident); 61 | 62 | IOEthernetController *getController(); 63 | 64 | IOCommandGate *getMainCommandGate(); 65 | 66 | IOWorkLoop *getMainWorkLoop(); 67 | 68 | private: 69 | IOEthernetController *controller; 70 | IOCommandGate *mainCommandGate; 71 | IOWorkLoop *mainWorkLoop; 72 | 73 | lck_grp_t *inner_gp; 74 | lck_grp_attr_t *inner_gp_attr; 75 | lck_attr_t *inner_attr; 76 | lck_mtx_t *inner_lock; 77 | }; 78 | 79 | #endif /* ItlHalService_hpp */ 80 | -------------------------------------------------------------------------------- /itl80211/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | IOKitPersonalities 22 | 23 | NSHumanReadableCopyright 24 | Copyright © 2020 钟先耀. All rights reserved. 25 | OSBundleLibraries 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /itl80211/linux/random.h: -------------------------------------------------------------------------------- 1 | // 2 | // random.h 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/22. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef random_h 24 | #define random_h 25 | 26 | #include 27 | 28 | static inline void get_random_bytes(void *buf, int nbytes) 29 | { 30 | random_buf(buf, nbytes); 31 | } 32 | 33 | #endif /* random_h */ 34 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * Copyright (c) 2016 Mike Belopuhov 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | 26 | #ifndef _AES_H_ 27 | #define _AES_H_ 28 | 29 | #ifndef AES_MAXROUNDS 30 | #define AES_MAXROUNDS (14) 31 | #endif 32 | 33 | typedef struct aes_ctx { 34 | uint32_t sk[60]; 35 | uint32_t sk_exp[120]; 36 | 37 | unsigned num_rounds; 38 | } AES_CTX; 39 | 40 | int AES_Setkey(AES_CTX *, const uint8_t *, int); 41 | void AES_Encrypt(AES_CTX *, const uint8_t *, uint8_t *); 42 | void AES_Decrypt(AES_CTX *, const uint8_t *, uint8_t *); 43 | void AES_Encrypt_ECB(AES_CTX *, const uint8_t *, uint8_t *, size_t); 44 | void AES_Decrypt_ECB(AES_CTX *, const uint8_t *, uint8_t *, size_t); 45 | 46 | int AES_KeySetup_Encrypt(uint32_t *, const uint8_t *, int); 47 | int AES_KeySetup_Decrypt(uint32_t *, const uint8_t *, int); 48 | 49 | #endif /* _AES_H_ */ 50 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/arc4.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: arc4.c,v 1.3 2007/09/11 12:07:05 djm Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Markus Friedl 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | 22 | #define RC4SWAP(x,y) \ 23 | do { \ 24 | u_int8_t t = ctx->state[x]; \ 25 | ctx->state[x] = ctx->state[y]; \ 26 | ctx->state[y] = t; \ 27 | } while(0) 28 | 29 | void 30 | rc4_keysetup(struct rc4_ctx *ctx, u_char *key, u_int32_t klen) 31 | { 32 | u_int8_t x, y; 33 | u_int32_t i; 34 | 35 | x = y = 0; 36 | for (i = 0; i < RC4STATE; i++) 37 | ctx->state[i] = i; 38 | for (i = 0; i < RC4STATE; i++) { 39 | y = (key[x] + ctx->state[i] + y) & (RC4STATE - 1); 40 | RC4SWAP(i, y); 41 | x = (x + 1) % klen; 42 | } 43 | ctx->x = ctx->y = 0; 44 | } 45 | 46 | void 47 | rc4_crypt(struct rc4_ctx *ctx, u_char *src, u_char *dst, 48 | u_int32_t len) 49 | { 50 | u_int32_t i; 51 | 52 | for (i = 0; i < len; i++) { 53 | ctx->x = (ctx->x + 1) & (RC4STATE - 1); 54 | ctx->y = (ctx->state[ctx->x] + ctx->y) & (RC4STATE - 1); 55 | RC4SWAP(ctx->x, ctx->y); 56 | dst[i] = src[i] ^ ctx->state[ 57 | (ctx->state[ctx->x] + ctx->state[ctx->y]) & (RC4STATE - 1)]; 58 | } 59 | } 60 | 61 | void 62 | rc4_getbytes(struct rc4_ctx *ctx, u_char *dst, u_int32_t len) 63 | { 64 | u_int32_t i; 65 | 66 | for (i = 0; i < len; i++) { 67 | ctx->x = (ctx->x + 1) & (RC4STATE - 1); 68 | ctx->y = (ctx->state[ctx->x] + ctx->y) & (RC4STATE - 1); 69 | RC4SWAP(ctx->x, ctx->y); 70 | dst[i] = ctx->state[ 71 | (ctx->state[ctx->x] + ctx->state[ctx->y]) & (RC4STATE - 1)]; 72 | } 73 | } 74 | 75 | void 76 | rc4_skip(struct rc4_ctx *ctx, u_int32_t len) 77 | { 78 | for (; len > 0; len--) { 79 | ctx->x = (ctx->x + 1) & (RC4STATE - 1); 80 | ctx->y = (ctx->state[ctx->x] + ctx->y) & (RC4STATE - 1); 81 | RC4SWAP(ctx->x, ctx->y); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/arc4.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: arc4.h,v 1.3 2007/09/11 12:07:05 djm Exp $ */ 2 | /* 3 | * Copyright (c) 2003 Markus Friedl 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #define RC4STATE 256 19 | #define RC4KEYLEN 16 20 | 21 | struct rc4_ctx { 22 | u_int8_t x, y; 23 | u_int8_t state[RC4STATE]; 24 | }; 25 | 26 | void rc4_keysetup(struct rc4_ctx *, u_char *, u_int32_t) 27 | __attribute__((__bounded__(__buffer__,2,3))); 28 | void rc4_crypt(struct rc4_ctx *, u_char *, u_char *, u_int32_t) 29 | __attribute__((__bounded__(__buffer__,2,4))) 30 | __attribute__((__bounded__(__buffer__,3,4))); 31 | void rc4_getbytes(struct rc4_ctx *, u_char *, u_int32_t) 32 | __attribute__((__bounded__(__buffer__,2,3))); 33 | void rc4_skip(struct rc4_ctx *, u_int32_t); 34 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/blf.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: blf.h,v 1.6 2007/02/21 19:25:40 grunk Exp $ */ 2 | 3 | /* 4 | * Blowfish - a fast block cipher designed by Bruce Schneier 5 | * 6 | * Copyright 1997 Niels Provos 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by Niels Provos. 20 | * 4. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _BLF_H_ 36 | #define _BLF_H_ 37 | 38 | /* Schneier states the maximum key length to be 56 bytes. 39 | * The way how the subkeys are initialized by the key up 40 | * to (N+2)*4 i.e. 72 bytes are utilized. 41 | * Warning: For normal blowfish encryption only 56 bytes 42 | * of the key affect all cipherbits. 43 | */ 44 | 45 | #define BLF_N 16 /* Number of Subkeys */ 46 | #define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ 47 | #define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */ 48 | 49 | /* Blowfish context */ 50 | typedef struct BlowfishContext { 51 | u_int32_t S[4][256]; /* S-Boxes */ 52 | u_int32_t P[BLF_N + 2]; /* Subkeys */ 53 | } blf_ctx; 54 | 55 | /* Raw access to customized Blowfish 56 | * blf_key is just: 57 | * Blowfish_initstate( state ) 58 | * Blowfish_expand0state( state, key, keylen ) 59 | */ 60 | 61 | void Blowfish_encipher(blf_ctx *, u_int32_t *); 62 | void Blowfish_decipher(blf_ctx *, u_int32_t *); 63 | void Blowfish_initstate(blf_ctx *); 64 | void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t); 65 | void Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t); 66 | 67 | /* Standard Blowfish */ 68 | 69 | void blf_key(blf_ctx *, const u_int8_t *, u_int16_t); 70 | void blf_enc(blf_ctx *, u_int32_t *, u_int16_t); 71 | void blf_dec(blf_ctx *, u_int32_t *, u_int16_t); 72 | 73 | /* Converts u_int8_t to u_int32_t */ 74 | u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , 75 | u_int16_t *); 76 | 77 | void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t); 78 | void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t); 79 | 80 | void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); 81 | void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); 82 | #endif 83 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/cast.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: cast.h,v 1.2 2002/03/14 01:26:51 millert Exp $ */ 2 | 3 | /* 4 | * CAST-128 in C 5 | * Written by Steve Reid 6 | * 100% Public Domain - no warranty 7 | * Released 1997.10.11 8 | */ 9 | 10 | #ifndef _CAST_H_ 11 | #define _CAST_H_ 12 | 13 | typedef struct { 14 | u_int32_t xkey[32]; /* Key, after expansion */ 15 | int rounds; /* Number of rounds to use, 12 or 16 */ 16 | } cast_key; 17 | 18 | void cast_setkey(cast_key * key, u_int8_t * rawkey, int keybytes); 19 | void cast_encrypt(cast_key * key, u_int8_t * inblock, u_int8_t * outblock); 20 | void cast_decrypt(cast_key * key, u_int8_t * inblock, u_int8_t * outblock); 21 | 22 | #endif /* ifndef _CAST_H_ */ 23 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/chachapoly.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Mike Belopuhov 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | int 25 | chacha20_setkey(void *sched, u_int8_t *key, int len) 26 | { 27 | struct chacha20_ctx *ctx = (struct chacha20_ctx *)sched; 28 | 29 | if (len != CHACHA20_KEYSIZE + CHACHA20_SALT) 30 | return (-1); 31 | 32 | /* initial counter is 1 */ 33 | ctx->nonce[0] = 1; 34 | memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE, 35 | CHACHA20_SALT); 36 | chacha_keysetup((chacha_ctx *)&ctx->block, key, CHACHA20_KEYSIZE * 8); 37 | return (0); 38 | } 39 | 40 | void 41 | chacha20_reinit(caddr_t key, u_int8_t *iv) 42 | { 43 | struct chacha20_ctx *ctx = (struct chacha20_ctx *)key; 44 | 45 | chacha_ivsetup((chacha_ctx *)ctx->block, iv, ctx->nonce); 46 | } 47 | 48 | void 49 | chacha20_crypt(caddr_t key, u_int8_t *data) 50 | { 51 | struct chacha20_ctx *ctx = (struct chacha20_ctx *)key; 52 | 53 | chacha_encrypt_bytes((chacha_ctx *)ctx->block, data, data, 54 | CHACHA20_BLOCK_LEN); 55 | } 56 | 57 | void 58 | Chacha20_Poly1305_Init(void *xctx) 59 | { 60 | CHACHA20_POLY1305_CTX *ctx = (CHACHA20_POLY1305_CTX *)xctx; 61 | 62 | memset(ctx, 0, sizeof(*ctx)); 63 | } 64 | 65 | void 66 | Chacha20_Poly1305_Setkey(void *xctx, const uint8_t *key, uint16_t klen) 67 | { 68 | CHACHA20_POLY1305_CTX *ctx = (CHACHA20_POLY1305_CTX *)xctx; 69 | 70 | /* salt is provided with the key material */ 71 | memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE, 72 | CHACHA20_SALT); 73 | chacha_keysetup((chacha_ctx *)&ctx->chacha, key, CHACHA20_KEYSIZE * 8); 74 | } 75 | 76 | void 77 | Chacha20_Poly1305_Reinit(void *xctx, const uint8_t *iv, uint16_t ivlen) 78 | { 79 | CHACHA20_POLY1305_CTX *ctx = (CHACHA20_POLY1305_CTX *)xctx; 80 | 81 | /* initial counter is 0 */ 82 | chacha_ivsetup((chacha_ctx *)&ctx->chacha, iv, ctx->nonce); 83 | chacha_encrypt_bytes((chacha_ctx *)&ctx->chacha, ctx->key, ctx->key, 84 | POLY1305_KEYLEN); 85 | poly1305_init((poly1305_state *)&ctx->poly, ctx->key); 86 | } 87 | 88 | int 89 | Chacha20_Poly1305_Update(void *xctx, const uint8_t *data, uint16_t len) 90 | { 91 | static const char zeroes[POLY1305_BLOCK_LEN] = {0}; 92 | CHACHA20_POLY1305_CTX *ctx = (CHACHA20_POLY1305_CTX *)xctx; 93 | size_t rem; 94 | 95 | poly1305_update((poly1305_state *)&ctx->poly, data, len); 96 | 97 | /* number of bytes in the last 16 byte block */ 98 | rem = (len + POLY1305_BLOCK_LEN) & (POLY1305_BLOCK_LEN - 1); 99 | if (rem > 0) 100 | poly1305_update((poly1305_state *)&ctx->poly, (const unsigned char *)zeroes, 101 | (size_t)(POLY1305_BLOCK_LEN - rem)); 102 | return (0); 103 | } 104 | 105 | void 106 | Chacha20_Poly1305_Final(uint8_t tag[POLY1305_TAGLEN], void *xctx) 107 | { 108 | CHACHA20_POLY1305_CTX *ctx = (CHACHA20_POLY1305_CTX *)xctx; 109 | 110 | poly1305_finish((poly1305_state *)&ctx->poly, tag); 111 | memset(ctx, 0, sizeof(*ctx)); 112 | } 113 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/chachapoly.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Mike Belopuhov 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _CHACHAPOLY_H_ 18 | #define _CHACHAPOLY_H_ 19 | 20 | #define CHACHA20_KEYSIZE 32 21 | #define CHACHA20_CTR 4 22 | #define CHACHA20_SALT 4 23 | #define CHACHA20_NONCE 8 24 | #define CHACHA20_BLOCK_LEN 64 25 | 26 | struct chacha20_ctx { 27 | uint8_t block[CHACHA20_BLOCK_LEN]; 28 | uint8_t nonce[CHACHA20_NONCE]; 29 | }; 30 | 31 | int chacha20_setkey(void *, u_int8_t *, int); 32 | void chacha20_reinit(caddr_t, u_int8_t *); 33 | void chacha20_crypt(caddr_t, u_int8_t *); 34 | 35 | 36 | #define POLY1305_KEYLEN 32 37 | #define POLY1305_TAGLEN 16 38 | #define POLY1305_BLOCK_LEN 16 39 | 40 | struct poly1305_ctx { 41 | /* r, h, pad, leftover */ 42 | unsigned long state[5+5+4]; 43 | size_t leftover; 44 | unsigned char buffer[POLY1305_BLOCK_LEN]; 45 | unsigned char final; 46 | }; 47 | 48 | typedef struct { 49 | uint8_t key[POLY1305_KEYLEN]; 50 | /* counter, salt */ 51 | uint8_t nonce[CHACHA20_NONCE]; 52 | struct chacha20_ctx chacha; 53 | struct poly1305_ctx poly; 54 | } CHACHA20_POLY1305_CTX; 55 | 56 | void Chacha20_Poly1305_Init(void *); 57 | void Chacha20_Poly1305_Setkey(void *, const uint8_t *, uint16_t); 58 | void Chacha20_Poly1305_Reinit(void *, const uint8_t *, uint16_t); 59 | int Chacha20_Poly1305_Update(void *, const uint8_t *, uint16_t); 60 | void Chacha20_Poly1305_Final(uint8_t[POLY1305_TAGLEN], void *); 61 | 62 | #endif /* _CHACHAPOLY_H_ */ 63 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/cmac.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: cmac.c,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Damien Bergamini 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * This code implements the CMAC (Cipher-based Message Authentication) 21 | * algorithm described in FIPS SP800-38B using the AES-128 cipher. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #define LSHIFT(v, r) do { \ 31 | int i; \ 32 | for (i = 0; i < 15; i++) \ 33 | (r)[i] = (v)[i] << 1 | (v)[i + 1] >> 7; \ 34 | (r)[15] = (v)[15] << 1; \ 35 | } while (0) 36 | 37 | #define XOR(v, r) do { \ 38 | int i; \ 39 | for (i = 0; i < 16; i++) \ 40 | (r)[i] ^= (v)[i]; \ 41 | } while (0) 42 | 43 | void 44 | AES_CMAC_Init(AES_CMAC_CTX *ctx) 45 | { 46 | memset(ctx->X, 0, sizeof ctx->X); 47 | ctx->M_n = 0; 48 | } 49 | 50 | void 51 | AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const u_int8_t key[AES_CMAC_KEY_LENGTH]) 52 | { 53 | AES_Setkey(&ctx->aesctx, key, 16); 54 | } 55 | 56 | void 57 | AES_CMAC_Update(AES_CMAC_CTX *ctx, const u_int8_t *data, u_int len) 58 | { 59 | u_int mlen; 60 | 61 | if (ctx->M_n > 0) { 62 | mlen = MIN(16 - ctx->M_n, len); 63 | memcpy(ctx->M_last + ctx->M_n, data, mlen); 64 | ctx->M_n += mlen; 65 | if (ctx->M_n < 16 || len == mlen) 66 | return; 67 | XOR(ctx->M_last, ctx->X); 68 | AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X); 69 | data += mlen; 70 | len -= mlen; 71 | } 72 | while (len > 16) { /* not last block */ 73 | XOR(data, ctx->X); 74 | AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X); 75 | data += 16; 76 | len -= 16; 77 | } 78 | /* potential last block, save it */ 79 | memcpy(ctx->M_last, data, len); 80 | ctx->M_n = len; 81 | } 82 | 83 | void 84 | AES_CMAC_Final(u_int8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *ctx) 85 | { 86 | u_int8_t K[16]; 87 | 88 | /* generate subkey K1 */ 89 | memset(K, 0, sizeof K); 90 | AES_Encrypt(&ctx->aesctx, K, K); 91 | 92 | if (K[0] & 0x80) { 93 | LSHIFT(K, K); 94 | K[15] ^= 0x87; 95 | } else 96 | LSHIFT(K, K); 97 | 98 | if (ctx->M_n == 16) { 99 | /* last block was a complete block */ 100 | XOR(K, ctx->M_last); 101 | } else { 102 | /* generate subkey K2 */ 103 | if (K[0] & 0x80) { 104 | LSHIFT(K, K); 105 | K[15] ^= 0x87; 106 | } else 107 | LSHIFT(K, K); 108 | 109 | /* padding(M_last) */ 110 | ctx->M_last[ctx->M_n] = 0x80; 111 | while (++ctx->M_n < 16) 112 | ctx->M_last[ctx->M_n] = 0; 113 | 114 | XOR(K, ctx->M_last); 115 | } 116 | XOR(ctx->M_last, ctx->X); 117 | AES_Encrypt(&ctx->aesctx, ctx->X, digest); 118 | 119 | memset(K, 0, sizeof K); 120 | } 121 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/cmac.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: cmac.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Damien Bergamini 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _CMAC_H_ 20 | #define _CMAC_H_ 21 | 22 | #define AES_CMAC_KEY_LENGTH 16 23 | #define AES_CMAC_DIGEST_LENGTH 16 24 | 25 | typedef struct _AES_CMAC_CTX { 26 | AES_CTX aesctx; 27 | u_int8_t X[16]; 28 | u_int8_t M_last[16]; 29 | u_int M_n; 30 | } AES_CMAC_CTX; 31 | 32 | //__BEGIN_DECLS 33 | void AES_CMAC_Init(AES_CMAC_CTX *); 34 | void AES_CMAC_SetKey(AES_CMAC_CTX *, const u_int8_t [AES_CMAC_KEY_LENGTH]); 35 | void AES_CMAC_Update(AES_CMAC_CTX *, const u_int8_t *, u_int) 36 | __attribute__((__bounded__(__string__,2,3))); 37 | void AES_CMAC_Final(u_int8_t [AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *) 38 | __attribute__((__bounded__(__minbytes__,1,AES_CMAC_DIGEST_LENGTH))); 39 | //__END_DECLS 40 | 41 | #endif /* _CMAC_H_ */ 42 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/ecb3_enc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ecb3_enc.c,v 1.3 2013/11/18 18:49:53 brad Exp $ */ 2 | 3 | /* lib/des/ecb3_enc.c */ 4 | /* Copyright (C) 1995 Eric Young (eay@mincom.oz.au) 5 | * All rights reserved. 6 | * 7 | * This file is part of an SSL implementation written 8 | * by Eric Young (eay@mincom.oz.au). 9 | * The implementation was written so as to conform with Netscapes SSL 10 | * specification. This library and applications are 11 | * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE 12 | * as long as the following conditions are aheared to. 13 | * 14 | * Copyright remains Eric Young's, and as such any Copyright notices in 15 | * the code are not to be removed. If this code is used in a product, 16 | * Eric Young should be given attribution as the author of the parts used. 17 | * This can be in the form of a textual message at program startup or 18 | * in documentation (online or textual) provided with the package. 19 | * 20 | * Redistribution and use in source and binary forms, with or without 21 | * modification, are permitted provided that the following conditions 22 | * are met: 23 | * 1. Redistributions of source code must retain the copyright 24 | * notice, this list of conditions and the following disclaimer. 25 | * 2. Redistributions in binary form must reproduce the above copyright 26 | * notice, this list of conditions and the following disclaimer in the 27 | * documentation and/or other materials provided with the distribution. 28 | * 3. All advertising materials mentioning features or use of this software 29 | * must display the following acknowledgement: 30 | * This product includes software developed by Eric Young (eay@mincom.oz.au) 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 33 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 | * SUCH DAMAGE. 43 | * 44 | * The licence and distribution terms for any publically available version or 45 | * derivative of this code cannot be changed. i.e. this code cannot simply be 46 | * copied and put under another distribution licence 47 | * [including the GNU Public Licence.] 48 | */ 49 | 50 | #include "des_locl.h" 51 | 52 | void 53 | des_ecb3_encrypt(des_cblock (*input), des_cblock (*output), 54 | des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3, 55 | int encrypt) 56 | { 57 | register u_int32_t l0, l1; 58 | register unsigned char *in, *out; 59 | u_int32_t ll[2]; 60 | 61 | in = (unsigned char *) input; 62 | out = (unsigned char *) output; 63 | c2l(in, l0); 64 | c2l(in, l1); 65 | IP(l0, l1); 66 | ll[0] = l0; 67 | ll[1] = l1; 68 | des_encrypt2(ll, ks1, encrypt); 69 | des_encrypt2(ll, ks2, !encrypt); 70 | des_encrypt2(ll, ks3, encrypt); 71 | l0 = ll[0]; 72 | l1 = ll[1]; 73 | FP(l1, l0); 74 | l2c(l0, out); 75 | l2c(l1, out); 76 | } 77 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/ecb_enc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ecb_enc.c,v 1.6 2015/12/10 21:00:51 naddy Exp $ */ 2 | 3 | /* lib/des/ecb_enc.c */ 4 | /* Copyright (C) 1995 Eric Young (eay@mincom.oz.au) 5 | * All rights reserved. 6 | * 7 | * This file is part of an SSL implementation written 8 | * by Eric Young (eay@mincom.oz.au). 9 | * The implementation was written so as to conform with Netscapes SSL 10 | * specification. This library and applications are 11 | * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE 12 | * as long as the following conditions are aheared to. 13 | * 14 | * Copyright remains Eric Young's, and as such any Copyright notices in 15 | * the code are not to be removed. If this code is used in a product, 16 | * Eric Young should be given attribution as the author of the parts used. 17 | * This can be in the form of a textual message at program startup or 18 | * in documentation (online or textual) provided with the package. 19 | * 20 | * Redistribution and use in source and binary forms, with or without 21 | * modification, are permitted provided that the following conditions 22 | * are met: 23 | * 1. Redistributions of source code must retain the copyright 24 | * notice, this list of conditions and the following disclaimer. 25 | * 2. Redistributions in binary form must reproduce the above copyright 26 | * notice, this list of conditions and the following disclaimer in the 27 | * documentation and/or other materials provided with the distribution. 28 | * 3. All advertising materials mentioning features or use of this software 29 | * must display the following acknowledgement: 30 | * This product includes software developed by Eric Young (eay@mincom.oz.au) 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 33 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 | * SUCH DAMAGE. 43 | * 44 | * The licence and distribution terms for any publically available version or 45 | * derivative of this code cannot be changed. i.e. this code cannot simply be 46 | * copied and put under another distribution licence 47 | * [including the GNU Public Licence.] 48 | */ 49 | 50 | #include "des_locl.h" 51 | #include "spr.h" 52 | 53 | void 54 | des_encrypt2(u_int32_t *data, des_key_schedule ks, int encrypt) 55 | { 56 | register u_int32_t l, r, t, u; 57 | #ifdef DES_USE_PTR 58 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; 59 | #endif 60 | register int i; 61 | register u_int32_t *s; 62 | 63 | u = data[0]; 64 | r = data[1]; 65 | 66 | /* Things have been modified so that the initial rotate is 67 | * done outside the loop. This required the 68 | * des_SPtrans values in sp.h to be rotated 1 bit to the right. 69 | * One perl script later and things have a 5% speed up on a sparc2. 70 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> 71 | * for pointing this out. */ 72 | l = (r << 1) | (r >> 31); 73 | r = (u << 1) | (u >> 31); 74 | 75 | /* clear the top bits on machines with 8byte longs */ 76 | l &= 0xffffffffL; 77 | r &= 0xffffffffL; 78 | 79 | s = (u_int32_t *) ks; 80 | /* I don't know if it is worth the effort of loop unrolling the 81 | * inner loop */ 82 | if (encrypt) { 83 | for (i = 0; i < 32; i += 4) { 84 | D_ENCRYPT(l, r, i + 0); /* 1 */ 85 | D_ENCRYPT(r, l, i + 2); /* 2 */ 86 | } 87 | } else { 88 | for (i = 30; i > 0; i -= 4) { 89 | D_ENCRYPT(l, r, i - 0); /* 16 */ 90 | D_ENCRYPT(r, l, i - 2); /* 15 */ 91 | } 92 | } 93 | l = (l >> 1) | (l << 31); 94 | r = (r >> 1) | (r << 31); 95 | /* clear the top bits on machines with 8byte longs */ 96 | l &= 0xffffffffL; 97 | r &= 0xffffffffL; 98 | 99 | data[0] = l; 100 | data[1] = r; 101 | l = r = t = u = 0; 102 | } 103 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/gmac.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: gmac.h,v 1.6 2017/05/02 11:44:32 mikeb Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2010 Mike Belopuhov 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _GMAC_H_ 20 | #define _GMAC_H_ 21 | 22 | #include 23 | 24 | #define GMAC_BLOCK_LEN 16 25 | #define GMAC_DIGEST_LEN 16 26 | 27 | typedef struct _GHASH_CTX { 28 | uint8_t H[GMAC_BLOCK_LEN]; /* hash subkey */ 29 | uint8_t S[GMAC_BLOCK_LEN]; /* state */ 30 | uint8_t Z[GMAC_BLOCK_LEN]; /* initial state */ 31 | } GHASH_CTX; 32 | 33 | typedef struct _AES_GMAC_CTX { 34 | GHASH_CTX ghash; 35 | AES_CTX K; 36 | uint8_t J[GMAC_BLOCK_LEN]; /* counter block */ 37 | } AES_GMAC_CTX; 38 | 39 | //__BEGIN_DECLS 40 | extern void (*ghash_update)(GHASH_CTX *, uint8_t *, size_t); 41 | 42 | void AES_GMAC_Init(void *); 43 | void AES_GMAC_Setkey(void *, const uint8_t *, uint16_t); 44 | void AES_GMAC_Reinit(void *, const uint8_t *, uint16_t); 45 | int AES_GMAC_Update(void *, const uint8_t *, uint16_t); 46 | void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], void *); 47 | //__END_DECLS 48 | 49 | #endif /* _GMAC_H_ */ 50 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/hmac.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: hmac.h,v 1.3 2012/12/05 23:20:15 deraadt Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Damien Bergamini 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _HMAC_H_ 20 | #define _HMAC_H_ 21 | 22 | #include "sha2.h" 23 | #include "md5.h" 24 | 25 | typedef struct _HMAC_MD5_CTX { 26 | MD5_CTX ctx; 27 | u_int8_t key[MD5_BLOCK_LENGTH]; 28 | u_int key_len; 29 | } HMAC_MD5_CTX; 30 | 31 | typedef struct _HMAC_SHA1_CTX { 32 | SHA1_CTX ctx; 33 | u_int8_t key[SHA1_BLOCK_LENGTH]; 34 | u_int key_len; 35 | } HMAC_SHA1_CTX; 36 | 37 | typedef struct _HMAC_SHA256_CTX { 38 | SHA2_CTX ctx; 39 | u_int8_t key[SHA256_BLOCK_LENGTH]; 40 | u_int key_len; 41 | } HMAC_SHA256_CTX; 42 | 43 | //__BEGIN_DECLS 44 | 45 | void HMAC_MD5_Init(HMAC_MD5_CTX *, const u_int8_t *, u_int) 46 | __attribute__((__bounded__(__string__,2,3))); 47 | void HMAC_MD5_Update(HMAC_MD5_CTX *, const u_int8_t *, u_int) 48 | __attribute__((__bounded__(__string__,2,3))); 49 | void HMAC_MD5_Final(u_int8_t [MD5_DIGEST_LENGTH], HMAC_MD5_CTX *) 50 | __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH))); 51 | 52 | void HMAC_SHA1_Init(HMAC_SHA1_CTX *, const u_int8_t *, u_int) 53 | __attribute__((__bounded__(__string__,2,3))); 54 | void HMAC_SHA1_Update(HMAC_SHA1_CTX *, const u_int8_t *, u_int) 55 | __attribute__((__bounded__(__string__,2,3))); 56 | void HMAC_SHA1_Final(u_int8_t [SHA1_DIGEST_LENGTH], HMAC_SHA1_CTX *) 57 | __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH))); 58 | 59 | void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const u_int8_t *, u_int) 60 | __attribute__((__bounded__(__string__,2,3))); 61 | void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const u_int8_t *, u_int) 62 | __attribute__((__bounded__(__string__,2,3))); 63 | void HMAC_SHA256_Final(u_int8_t [SHA256_DIGEST_LENGTH], HMAC_SHA256_CTX *) 64 | __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); 65 | 66 | //__END_DECLS 67 | 68 | #endif /* _HMAC_H_ */ 69 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/idgen.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: idgen.h,v 1.3 2013/06/05 05:45:54 djm Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Damien Miller 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #define IDGEN32_ROUNDS 31 19 | #define IDGEN32_KEYLEN 32 20 | #define IDGEN32_REKEY_LIMIT 0x60000000 21 | #define IDGEN32_REKEY_TIME 600 22 | 23 | struct idgen32_ctx { 24 | u_int32_t id32_counter; 25 | u_int32_t id32_offset; 26 | u_int32_t id32_hibit; 27 | u_int8_t id32_key[IDGEN32_KEYLEN]; 28 | time_t id32_rekey_time; 29 | }; 30 | 31 | void idgen32_init(struct idgen32_ctx *); 32 | u_int32_t idgen32(struct idgen32_ctx *); 33 | 34 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/key_wrap.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: key_wrap.c,v 1.5 2017/05/02 17:07:06 mikeb Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Damien Bergamini 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * This code implements the AES Key Wrap algorithm described in RFC 3394. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | static const u_int8_t IV[8] = 31 | { 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6 }; 32 | 33 | void 34 | aes_key_wrap_set_key(aes_key_wrap_ctx *ctx, const u_int8_t *K, size_t K_len) 35 | { 36 | AES_Setkey(&ctx->ctx, K, K_len); 37 | } 38 | 39 | void 40 | aes_key_wrap_set_key_wrap_only(aes_key_wrap_ctx *ctx, const u_int8_t *K, 41 | size_t K_len) 42 | { 43 | AES_Setkey(&ctx->ctx, K, K_len); 44 | } 45 | 46 | void 47 | aes_key_wrap(aes_key_wrap_ctx *ctx, const u_int8_t *P, size_t n, u_int8_t *C) 48 | { 49 | u_int64_t B[2], t; 50 | u_int8_t *A, *R; 51 | size_t i; 52 | int j; 53 | 54 | memmove(C + 8, P, n * 8); /* P and C may overlap */ 55 | A = C; /* A points to C[0] */ 56 | memcpy(A, IV, 8); /* A = IV, an initial value */ 57 | 58 | for (j = 0, t = 1; j <= 5; j++) { 59 | R = C + 8; 60 | for (i = 1; i <= n; i++, t++) { 61 | /* B = A | R[i] */ 62 | memcpy(&B[0], A, 8); 63 | memcpy(&B[1], R, 8); 64 | /* B = AES(K, B) */ 65 | AES_Encrypt(&ctx->ctx, (const uint8_t *)(caddr_t)B, (uint8_t *)(caddr_t)B); 66 | /* MSB(64, B) = MSB(64, B) ^ t */ 67 | B[0] ^= htobe64(t); 68 | /* A = MSB(64, B) */ 69 | memcpy(A, &B[0], 8); 70 | /* R[i] = LSB(64, B) */ 71 | memcpy(R, &B[1], 8); 72 | 73 | R += 8; 74 | } 75 | } 76 | memset(B, 0, sizeof B); 77 | } 78 | 79 | int 80 | aes_key_unwrap(aes_key_wrap_ctx *ctx, const u_int8_t *C, u_int8_t *P, size_t n) 81 | { 82 | u_int64_t B[2], t; 83 | u_int8_t A[8], *R; 84 | size_t i; 85 | int j; 86 | 87 | memcpy(A, C, 8); /* A = C[0] */ 88 | memmove(P, C + 8, n * 8); /* P and C may overlap */ 89 | 90 | for (j = 5, t = 6 * n; j >= 0; j--) { 91 | R = P + (n - 1) * 8; 92 | for (i = n; i >= 1; i--, t--) { 93 | /* MSB(64, B) = A */ 94 | memcpy(&B[0], A, 8); 95 | /* MSB(64, B) = MSB(64, B) ^ t */ 96 | B[0] ^= htobe64(t); 97 | /* B = MSB(64, B) | R[i] */ 98 | memcpy(&B[1], R, 8); 99 | /* B = AES-1(K, B) */ 100 | AES_Decrypt(&ctx->ctx, (const uint8_t *)(caddr_t)B, (uint8_t *)(caddr_t)B); 101 | /* A = MSB(64, B) */ 102 | memcpy(A, &B[0], 8); 103 | /* R[i] = LSB(64, B) */ 104 | memcpy(R, &B[1], 8); 105 | 106 | R -= 8; 107 | } 108 | } 109 | memset(B, 0, sizeof B); 110 | 111 | /* check that A is an appropriate initial value */ 112 | return timingsafe_bcmp(A, IV, 8) != 0; 113 | } 114 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/key_wrap.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: key_wrap.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Damien Bergamini 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _KEY_WRAP_H_ 20 | #define _KEY_WRAP_H_ 21 | 22 | extern int timingsafe_bcmp(const void *b1, const void *b2, size_t n); 23 | 24 | typedef struct _aes_key_wrap_ctx { 25 | AES_CTX ctx; 26 | } aes_key_wrap_ctx; 27 | 28 | //__BEGIN_DECLS 29 | 30 | void aes_key_wrap_set_key(aes_key_wrap_ctx *, const u_int8_t *, size_t); 31 | void aes_key_wrap_set_key_wrap_only(aes_key_wrap_ctx *, const u_int8_t *, 32 | size_t); 33 | void aes_key_wrap(aes_key_wrap_ctx *, const u_int8_t *, size_t, u_int8_t *); 34 | int aes_key_unwrap(aes_key_wrap_ctx *, const u_int8_t *, u_int8_t *, 35 | size_t); 36 | //__END_DECLS 37 | 38 | #endif /* _KEY_WRAP_H_ */ 39 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/md5.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: md5.h,v 1.3 2014/11/16 17:39:09 tedu Exp $ */ 2 | 3 | /* 4 | * This code implements the MD5 message-digest algorithm. 5 | * The algorithm is due to Ron Rivest. This code was 6 | * written by Colin Plumb in 1993, no copyright is claimed. 7 | * This code is in the public domain; do with it what you wish. 8 | * 9 | * Equivalent code is available from RSA Data Security, Inc. 10 | * This code has been tested against that, and is equivalent, 11 | * except that you don't need to include two pages of legalese 12 | * with every copy. 13 | */ 14 | 15 | #ifndef _MD5_H_ 16 | #define _MD5_H_ 17 | 18 | #define MD5_BLOCK_LENGTH 64 19 | #define MD5_DIGEST_LENGTH 16 20 | 21 | typedef struct MD5Context { 22 | u_int32_t state[4]; /* state */ 23 | u_int64_t count; /* number of bits, mod 2^64 */ 24 | u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ 25 | } MD5_CTX; 26 | 27 | //__BEGIN_DECLS 28 | void MD5Init(MD5_CTX *); 29 | void MD5Update(MD5_CTX *, const void *, size_t) 30 | __attribute__((__bounded__(__string__,2,3))); 31 | void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *) 32 | __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH))); 33 | void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]) 34 | __attribute__((__bounded__(__minbytes__,1,4))) 35 | __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH))); 36 | //__END_DECLS 37 | 38 | #endif /* _MD5_H_ */ 39 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/michael.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: michael.c,v 1.2 2008/07/21 19:52:45 damien Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2005, 2006 Reyk Floeter 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* 20 | * Implementation of the Michael MIC as defined in IEEE 802.11i for TKIP. 21 | * The MIC generates a 64bit digest, which shouldn't be used for any other 22 | * applications except TKIP. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #define ROL(n, x) (((x) << (n)) | ((x) >> (32 - (n)))) 31 | #define ROR(n, x) (((x) >> (n)) | ((x) << (32 - (n)))) 32 | #define XSWAP(x) (((x) & 0xff00ff00UL) >> 8 | ((x) & 0x00ff00ffUL) << 8) 33 | 34 | #if defined(__STRICT_ALIGNMENT) || _BYTE_ORDER != _LITTLE_ENDIAN 35 | #define GETLE32(x) ((x)[0] | (x)[1] << 8 | (x)[2] << 16 | (x)[3] << 24) 36 | #define PUTLE32(x, v) ((x)[0] = (u_int8_t)(v), \ 37 | (x)[1] = (u_int8_t)((v) >> 8), \ 38 | (x)[2] = (u_int8_t)((v) >> 16), \ 39 | (x)[3] = (u_int8_t)((v) >> 24)) 40 | #else 41 | #define GETLE32(x) (*((u_int32_t *)(x))) 42 | #define PUTLE32(x, v) (*((u_int32_t *)(x)) = (v)) 43 | #endif 44 | 45 | #define MICHAEL_BLOCK(l, r) do { \ 46 | r ^= ROL(17, l); \ 47 | l += r; \ 48 | r ^= XSWAP(l); \ 49 | l += r; \ 50 | r ^= ROL(3, l); \ 51 | l += r; \ 52 | r ^= ROR(2, l); \ 53 | l += r; \ 54 | } while (0) 55 | 56 | void 57 | michael_init(MICHAEL_CTX *ctx) 58 | { 59 | bzero(ctx, sizeof(MICHAEL_CTX)); 60 | } 61 | 62 | void 63 | michael_update(MICHAEL_CTX *ctx, const u_int8_t *data, u_int len) 64 | { 65 | int i; 66 | 67 | for (i = 0; i < len; i++) { 68 | ctx->michael_state |= data[i] << (ctx->michael_count << 3); 69 | ctx->michael_count++; 70 | 71 | if (ctx->michael_count >= MICHAEL_RAW_BLOCK_LENGTH) { 72 | ctx->michael_l ^= ctx->michael_state; 73 | MICHAEL_BLOCK(ctx->michael_l, ctx->michael_r); 74 | ctx->michael_state = ctx->michael_count = 0; 75 | } 76 | } 77 | } 78 | 79 | void 80 | michael_final(u_int8_t digest[MICHAEL_DIGEST_LENGTH], MICHAEL_CTX *ctx) 81 | { 82 | static const u_int8_t pad[] = 83 | { 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 84 | 85 | michael_update(ctx, pad, sizeof(pad)); 86 | 87 | PUTLE32(digest, ctx->michael_l); 88 | PUTLE32(digest + MICHAEL_RAW_BLOCK_LENGTH, ctx->michael_r); 89 | } 90 | 91 | void 92 | michael_key(const u_int8_t *key, MICHAEL_CTX *ctx) 93 | { 94 | ctx->michael_l = ctx->michael_key[0] = 95 | GETLE32(key); 96 | ctx->michael_r = ctx->michael_key[1] = 97 | GETLE32(key + MICHAEL_RAW_BLOCK_LENGTH); 98 | } 99 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/michael.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: michael.h,v 1.2 2012/12/05 23:20:15 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2005, 2006 Reyk Floeter 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _MICHAEL_H_ 20 | #define _MICHAEL_H_ 21 | 22 | #define MICHAEL_BLOCK_LENGTH 8 23 | #define MICHAEL_RAW_BLOCK_LENGTH 4 24 | #define MICHAEL_DIGEST_LENGTH 8 25 | 26 | typedef struct michael_context { 27 | u_int32_t michael_key[2]; 28 | u_int32_t michael_l, michael_r; 29 | u_int32_t michael_state; 30 | u_int michael_count; 31 | } MICHAEL_CTX; 32 | 33 | //__BEGIN_DECLS 34 | void michael_init(MICHAEL_CTX *); 35 | void michael_update(MICHAEL_CTX *, const u_int8_t *, u_int) 36 | __attribute__((__bounded__(__buffer__, 2, 3))); 37 | void michael_final(u_int8_t [MICHAEL_DIGEST_LENGTH], MICHAEL_CTX *) 38 | __attribute__((__bounded__(__minbytes__, 1, 39 | MICHAEL_DIGEST_LENGTH))); 40 | void michael_key(const u_int8_t *, MICHAEL_CTX *) 41 | __attribute__((__bounded__(__minbytes__, 1, 42 | MICHAEL_BLOCK_LENGTH))); 43 | //__END_DECLS 44 | 45 | #endif /* _MICHAEL_H_ */ 46 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/podd.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: podd.h,v 1.1 2000/02/28 23:13:05 deraadt Exp $ */ 2 | 3 | /* lib/des/podd.h */ 4 | /* Copyright (C) 1995 Eric Young (eay@mincom.oz.au) 5 | * All rights reserved. 6 | * 7 | * This file is part of an SSL implementation written 8 | * by Eric Young (eay@mincom.oz.au). 9 | * The implementation was written so as to conform with Netscapes SSL 10 | * specification. This library and applications are 11 | * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE 12 | * as long as the following conditions are aheared to. 13 | * 14 | * Copyright remains Eric Young's, and as such any Copyright notices in 15 | * the code are not to be removed. If this code is used in a product, 16 | * Eric Young should be given attribution as the author of the parts used. 17 | * This can be in the form of a textual message at program startup or 18 | * in documentation (online or textual) provided with the package. 19 | * 20 | * Redistribution and use in source and binary forms, with or without 21 | * modification, are permitted provided that the following conditions 22 | * are met: 23 | * 1. Redistributions of source code must retain the copyright 24 | * notice, this list of conditions and the following disclaimer. 25 | * 2. Redistributions in binary form must reproduce the above copyright 26 | * notice, this list of conditions and the following disclaimer in the 27 | * documentation and/or other materials provided with the distribution. 28 | * 3. All advertising materials mentioning features or use of this software 29 | * must display the following acknowledgement: 30 | * This product includes software developed by Eric Young (eay@mincom.oz.au) 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 33 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 | * SUCH DAMAGE. 43 | * 44 | * The licence and distribution terms for any publically available version or 45 | * derivative of this code cannot be changed. i.e. this code cannot simply be 46 | * copied and put under another distribution licence 47 | * [including the GNU Public Licence.] 48 | */ 49 | 50 | static const unsigned char odd_parity[256]={ 51 | 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14, 52 | 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31, 53 | 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47, 54 | 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62, 55 | 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79, 56 | 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94, 57 | 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110, 58 | 112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127, 59 | 128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143, 60 | 145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158, 61 | 161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174, 62 | 176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191, 63 | 193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206, 64 | 208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223, 65 | 224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239, 66 | 241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254}; 67 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/poly1305.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Public Domain poly1305 from Andrew Moon 3 | * 4 | * poly1305 implementation using 32 bit * 32 bit = 64 bit multiplication 5 | * and 64 bit addition from https://github.com/floodyberry/poly1305-donna 6 | */ 7 | 8 | #ifndef _POLY1305_H_ 9 | #define _POLY1305_H_ 10 | 11 | #define poly1305_block_size 16 12 | 13 | typedef struct poly1305_state { 14 | unsigned long r[5]; 15 | unsigned long h[5]; 16 | unsigned long pad[4]; 17 | size_t leftover; 18 | unsigned char buffer[poly1305_block_size]; 19 | unsigned char final; 20 | } poly1305_state; 21 | 22 | void poly1305_init(poly1305_state *, const unsigned char[32]); 23 | void poly1305_update(poly1305_state *, const unsigned char *, size_t); 24 | void poly1305_finish(poly1305_state *, unsigned char[16]); 25 | 26 | #endif /* _POLY1305_H_ */ 27 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/rijndael.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: rijndael.h,v 1.13 2008/06/09 07:49:45 djm Exp $ */ 2 | 3 | /** 4 | * rijndael-alg-fst.h 5 | * 6 | * @version 3.0 (December 2000) 7 | * 8 | * Optimised ANSI C code for the Rijndael cipher (now AES) 9 | * 10 | * @author Vincent Rijmen 11 | * @author Antoon Bosselaers 12 | * @author Paulo Barreto 13 | * 14 | * This code is hereby placed in the public domain. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 17 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | #ifndef __RIJNDAEL_H 29 | #define __RIJNDAEL_H 30 | 31 | #define AES_MAXKEYBITS (256) 32 | #define AES_MAXKEYBYTES (AES_MAXKEYBITS/8) 33 | /* for 256-bit keys, fewer for less */ 34 | #define AES_MAXROUNDS 14 35 | 36 | typedef unsigned char u8; 37 | typedef unsigned short u16; 38 | typedef unsigned int u32; 39 | 40 | /* The structure for key information */ 41 | typedef struct { 42 | int enc_only; /* context contains only encrypt schedule */ 43 | int Nr; /* key-length-dependent number of rounds */ 44 | u32 ek[4*(AES_MAXROUNDS + 1)]; /* encrypt key schedule */ 45 | u32 dk[4*(AES_MAXROUNDS + 1)]; /* decrypt key schedule */ 46 | } rijndael_ctx; 47 | 48 | int rijndael_set_key(rijndael_ctx *, const u_char *, int); 49 | int rijndael_set_key_enc_only(rijndael_ctx *, const u_char *, int); 50 | void rijndael_decrypt(rijndael_ctx *, const u_char *, u_char *); 51 | void rijndael_encrypt(rijndael_ctx *, const u_char *, u_char *); 52 | 53 | int rijndaelKeySetupEnc(unsigned int [], const unsigned char [], int); 54 | int rijndaelKeySetupDec(unsigned int [], const unsigned char [], int); 55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], 56 | unsigned char []); 57 | 58 | #endif /* __RIJNDAEL_H */ 59 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/rmd160.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: rmd160.h,v 1.5 2009/07/05 19:33:46 millert Exp $ */ 2 | /* 3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | #ifndef _RMD160_H 26 | #define _RMD160_H 27 | 28 | #define RMD160_BLOCK_LENGTH 64 29 | #define RMD160_DIGEST_LENGTH 20 30 | 31 | /* RMD160 context. */ 32 | typedef struct RMD160Context { 33 | u_int32_t state[5]; /* state */ 34 | u_int64_t count; /* number of bits, mod 2^64 */ 35 | u_char buffer[RMD160_BLOCK_LENGTH]; /* input buffer */ 36 | } RMD160_CTX; 37 | 38 | //__BEGIN_DECLS 39 | void RMD160Init(RMD160_CTX *); 40 | void RMD160Transform(u_int32_t [5], const u_char [RMD160_BLOCK_LENGTH]) 41 | __attribute__((__bounded__(__minbytes__,1,5))) 42 | __attribute__((__bounded__(__minbytes__,2,RMD160_BLOCK_LENGTH))); 43 | void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t) 44 | __attribute__((__bounded__(__string__,2,3))); 45 | void RMD160Final(u_char [RMD160_DIGEST_LENGTH], RMD160_CTX *) 46 | __attribute__((__bounded__(__minbytes__,1,RMD160_DIGEST_LENGTH))); 47 | //__END_DECLS 48 | 49 | #endif /* _RMD160_H */ 50 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/sha1-pbkdf2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SHA1-based key derivation function (PBKDF2) for IEEE 802.11i 3 | * Copyright (c) 2003-2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #include "sha1.h" 10 | #include "hmac.h" 11 | 12 | static int openssl_hmac_vector(const u8 *key, 13 | size_t key_len, size_t num_elem, 14 | const u8 *addr[], const size_t *len, u8 *mac, 15 | unsigned int mdlen) 16 | { 17 | HMAC_SHA1_CTX ctx; 18 | size_t i; 19 | u_int8_t digest[SHA1_DIGEST_LENGTH]; 20 | 21 | HMAC_SHA1_Init(&ctx, key, key_len); 22 | 23 | for (i = 0; i < num_elem; i++) 24 | HMAC_SHA1_Update(&ctx, addr[i], len[i]); 25 | 26 | HMAC_SHA1_Final(digest, &ctx); 27 | memcpy(mac, digest, sizeof(digest)); 28 | 29 | return 0; 30 | } 31 | 32 | int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem, 33 | const u8 *addr[], const size_t *len, u8 *mac) 34 | { 35 | return openssl_hmac_vector(key, key_len, num_elem, addr, 36 | len, mac, 20); 37 | } 38 | 39 | 40 | int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len, 41 | u8 *mac) 42 | { 43 | return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac); 44 | } 45 | 46 | static int pbkdf2_sha1_f(const char *passphrase, const u8 *ssid, 47 | size_t ssid_len, int iterations, unsigned int count, 48 | u8 *digest) 49 | { 50 | unsigned char tmp[SHA1_MAC_LEN], tmp2[SHA1_MAC_LEN]; 51 | int i, j; 52 | unsigned char count_buf[4]; 53 | const u8 *addr[2]; 54 | size_t len[2]; 55 | size_t passphrase_len = strlen(passphrase); 56 | 57 | addr[0] = ssid; 58 | len[0] = ssid_len; 59 | addr[1] = count_buf; 60 | len[1] = 4; 61 | 62 | /* F(P, S, c, i) = U1 xor U2 xor ... Uc 63 | * U1 = PRF(P, S || i) 64 | * U2 = PRF(P, U1) 65 | * Uc = PRF(P, Uc-1) 66 | */ 67 | 68 | count_buf[0] = (count >> 24) & 0xff; 69 | count_buf[1] = (count >> 16) & 0xff; 70 | count_buf[2] = (count >> 8) & 0xff; 71 | count_buf[3] = count & 0xff; 72 | if (hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len, 73 | tmp)) 74 | return -1; 75 | memcpy(digest, tmp, SHA1_MAC_LEN); 76 | 77 | for (i = 1; i < iterations; i++) { 78 | if (hmac_sha1((u8 *) passphrase, passphrase_len, tmp, 79 | SHA1_MAC_LEN, tmp2)) 80 | return -1; 81 | memcpy(tmp, tmp2, SHA1_MAC_LEN); 82 | for (j = 0; j < SHA1_MAC_LEN; j++) 83 | digest[j] ^= tmp2[j]; 84 | } 85 | 86 | return 0; 87 | } 88 | 89 | 90 | /** 91 | * pbkdf2_sha1 - SHA1-based key derivation function (PBKDF2) for IEEE 802.11i 92 | * @passphrase: ASCII passphrase 93 | * @ssid: SSID 94 | * @ssid_len: SSID length in bytes 95 | * @iterations: Number of iterations to run 96 | * @buf: Buffer for the generated key 97 | * @buflen: Length of the buffer in bytes 98 | * Returns: 0 on success, -1 of failure 99 | * 100 | * This function is used to derive PSK for WPA-PSK. For this protocol, 101 | * iterations is set to 4096 and buflen to 32. This function is described in 102 | * IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0. 103 | */ 104 | int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len, 105 | int iterations, u8 *buf, size_t buflen) 106 | { 107 | unsigned int count = 0; 108 | unsigned char *pos = buf; 109 | size_t left = buflen, plen; 110 | unsigned char digest[SHA1_MAC_LEN]; 111 | 112 | while (left > 0) { 113 | count++; 114 | if (pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations, 115 | count, digest)) 116 | return -1; 117 | plen = left > SHA1_MAC_LEN ? SHA1_MAC_LEN : left; 118 | memcpy(pos, digest, plen); 119 | pos += plen; 120 | left -= plen; 121 | } 122 | 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/sha1.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: sha1.h,v 1.6 2014/11/16 17:39:09 tedu Exp $ */ 2 | 3 | /* 4 | * SHA-1 in C 5 | * By Steve Reid 6 | * 100% Public Domain 7 | */ 8 | 9 | #ifndef _SHA1_H_ 10 | #define _SHA1_H_ 11 | 12 | #include "types.h" 13 | 14 | #define SHA1_MAC_LEN 20 15 | 16 | #define SHA1_BLOCK_LENGTH 64 17 | #define SHA1_DIGEST_LENGTH 20 18 | 19 | typedef struct { 20 | u_int32_t state[5]; 21 | u_int64_t count; 22 | unsigned char buffer[SHA1_BLOCK_LENGTH]; 23 | } SHA1_CTX; 24 | 25 | void SHA1Init(SHA1_CTX * context); 26 | void SHA1Transform(u_int32_t state[5], const unsigned char buffer[SHA1_BLOCK_LENGTH]); 27 | void SHA1Update(SHA1_CTX *context, const void *data, unsigned int len); 28 | void SHA1Final(unsigned char digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context); 29 | 30 | int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem, 31 | const u8 *addr[], const size_t *len, u8 *mac); 32 | int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len, 33 | u8 *mac); 34 | int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len, 35 | int iterations, u8 *buf, size_t buflen); 36 | #endif /* _SHA1_H_ */ 37 | -------------------------------------------------------------------------------- /itl80211/openbsd/crypto/sha2.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: sha2.h,v 1.5 2014/11/16 17:39:09 tedu Exp $ */ 2 | 3 | /* 4 | * FILE: sha2.h 5 | * AUTHOR: Aaron D. Gifford 6 | * 7 | * Copyright (c) 2000-2001, Aaron D. Gifford 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | * 34 | * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 35 | */ 36 | 37 | #ifndef _SHA2_H 38 | #define _SHA2_H 39 | 40 | 41 | /*** SHA-256/384/512 Various Length Definitions ***********************/ 42 | #define SHA256_BLOCK_LENGTH 64 43 | #define SHA256_DIGEST_LENGTH 32 44 | #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 45 | #define SHA384_BLOCK_LENGTH 128 46 | #define SHA384_DIGEST_LENGTH 48 47 | #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 48 | #define SHA512_BLOCK_LENGTH 128 49 | #define SHA512_DIGEST_LENGTH 64 50 | #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 51 | 52 | 53 | /*** SHA-256/384/512 Context Structure *******************************/ 54 | typedef struct _SHA2_CTX { 55 | union { 56 | u_int32_t st32[8]; 57 | u_int64_t st64[8]; 58 | } state; 59 | u_int64_t bitcount[2]; 60 | u_int8_t buffer[SHA512_BLOCK_LENGTH]; 61 | } SHA2_CTX; 62 | 63 | //__BEGIN_DECLS 64 | void SHA256Init(SHA2_CTX *); 65 | void SHA256Update(SHA2_CTX *, const void *, size_t) 66 | __attribute__((__bounded__(__string__,2,3))); 67 | void SHA256Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA2_CTX *) 68 | __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); 69 | 70 | void SHA384Init(SHA2_CTX *); 71 | void SHA384Update(SHA2_CTX *, const void *, size_t) 72 | __attribute__((__bounded__(__string__,2,3))); 73 | void SHA384Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA2_CTX *) 74 | __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); 75 | 76 | void SHA512Init(SHA2_CTX *); 77 | void SHA512Update(SHA2_CTX *, const void *, size_t) 78 | __attribute__((__bounded__(__string__,2,3))); 79 | void SHA512Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA2_CTX *) 80 | __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); 81 | //__END_DECLS 82 | 83 | #endif /* _SHA2_H */ 84 | -------------------------------------------------------------------------------- /itl80211/openbsd/net80211/CTimeout.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CTimeout.cpp 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/30. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #include 24 | 25 | void CTimeout::timeoutOccurred(OSObject* owner, IOTimerEventSource* timer) 26 | { 27 | // IOLog("itlwm %s\n", __FUNCTION__); 28 | if (owner == NULL) { 29 | IOLog("itlwm tm owner == NULL!!!\n"); 30 | } 31 | CTimeout *tm = OSDynamicCast(CTimeout, owner); 32 | if (tm == NULL) { 33 | IOLog("itlwm tm == NULL!!!\n"); 34 | return; 35 | } 36 | //callback 37 | tm->isPending = false; 38 | tm->to_func(tm->to_arg); 39 | } 40 | 41 | IOReturn CTimeout::timeout_add_msec(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 42 | { 43 | IOWorkLoop *wl = (IOWorkLoop*)arg1; 44 | int msecs = *(int*)arg2; 45 | CTimeout **ccto = (CTimeout **)arg0; 46 | 47 | if (ccto == NULL || *ccto == NULL) { 48 | return kIOReturnError; 49 | } 50 | CTimeout *cto = *ccto; 51 | if (cto->tm == NULL) { 52 | cto->tm = IOTimerEventSource::timerEventSource(cto, &CTimeout::timeoutOccurred); 53 | if (cto->tm == NULL) { 54 | return kIOReturnError; 55 | } 56 | cto->tm->enable(); 57 | wl->addEventSource(cto->tm); 58 | } 59 | cto->tm->setTimeoutMS(msecs); 60 | cto->isPending = true; 61 | return kIOReturnSuccess; 62 | } 63 | 64 | IOReturn CTimeout::timeout_del(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 65 | { 66 | CTimeout **ccto = (CTimeout **)arg0; 67 | if (ccto == NULL || *ccto == NULL) { 68 | return kIOReturnSuccess; 69 | } 70 | CTimeout *cto = *ccto; 71 | if (cto->tm == NULL || !cto->isPending) { 72 | return kIOReturnSuccess; 73 | } 74 | cto->tm->cancelTimeout(); 75 | cto->isPending = false; 76 | return kIOReturnSuccess; 77 | } 78 | 79 | IOReturn CTimeout::timeout_free(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 80 | { 81 | CTimeout **cto = (CTimeout **)arg0; 82 | IOWorkLoop *wl = (IOWorkLoop*)arg1; 83 | if (cto == NULL || *cto == NULL) { 84 | return kIOReturnSuccess; 85 | } 86 | CTimeout *tm = *cto; 87 | if (tm->tm != NULL) { 88 | wl->removeEventSource(tm->tm); 89 | tm->tm->release(); 90 | tm->tm = NULL; 91 | } 92 | tm->release(); 93 | *cto = NULL; 94 | return kIOReturnSuccess; 95 | } 96 | 97 | typedef void (*callback)(void *); 98 | 99 | IOReturn CTimeout::timeout_set(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 100 | { 101 | CTimeout *tm; 102 | CTimeout **cto = (CTimeout **)arg0; 103 | if (cto == NULL) { 104 | return kIOReturnError; 105 | } 106 | if ((*cto) == NULL) { 107 | *cto = new CTimeout; 108 | } 109 | tm = *cto; 110 | tm->isPending = false; 111 | tm->to_func = (callback)arg1; 112 | tm->to_arg = arg2; 113 | return kIOReturnSuccess; 114 | } 115 | 116 | IOReturn CTimeout::timeout_pending(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 117 | { 118 | CTimeout **cto = (CTimeout **)arg0; 119 | CTimeout *tm; 120 | if (cto == NULL) { 121 | return kIOReturnError; 122 | } 123 | tm = *cto; 124 | if (tm != NULL && tm->isPending) { 125 | return kIOReturnSuccess; 126 | } 127 | return kIOReturnError; 128 | } 129 | -------------------------------------------------------------------------------- /itl80211/openbsd/net80211/_string.c: -------------------------------------------------------------------------------- 1 | // 2 | // _string.h 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/30. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef _string_c 24 | #define _string_c 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int timingsafe_bcmp(const void *b1, const void *b2, size_t n) 31 | { 32 | const unsigned char *p1 = (const unsigned char *)b1, *p2 = (const unsigned char *)b2; 33 | int ret = 0; 34 | 35 | for (; n > 0; n--) 36 | ret |= *p1++ ^ *p2++; 37 | return (ret != 0); 38 | } 39 | 40 | 41 | 42 | 43 | #endif /* _string_c */ 44 | -------------------------------------------------------------------------------- /itl80211/openbsd/net80211/ieee80211_amrr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | /* $OpenBSD: ieee80211_amrr.c,v 1.12 2019/02/24 09:36:28 stsp Exp $ */ 15 | 16 | /*- 17 | * Copyright (c) 2006 18 | * Damien Bergamini 19 | * 20 | * Permission to use, copy, modify, and distribute this software for any 21 | * purpose with or without fee is hereby granted, provided that the above 22 | * copyright notice and this permission notice appear in all copies. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 25 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 26 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 27 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 29 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #define is_success(amn) \ 49 | ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10) 50 | #define is_failure(amn) \ 51 | ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3) 52 | #define is_enough(amn) \ 53 | ((amn)->amn_txcnt > 10) 54 | #define reset_cnt(amn) \ 55 | do { (amn)->amn_txcnt = (amn)->amn_retrycnt = 0; } while (0) 56 | 57 | static inline int 58 | is_min_rate(struct ieee80211_node *ni) 59 | { 60 | return (ni->ni_txrate == 0); 61 | } 62 | 63 | static inline int 64 | is_max_rate(struct ieee80211_node *ni) 65 | { 66 | return (ni->ni_txrate == ni->ni_rates.rs_nrates - 1); 67 | } 68 | 69 | static inline void 70 | increase_rate(struct ieee80211_node *ni) 71 | { 72 | ni->ni_txrate++; 73 | } 74 | 75 | static inline void 76 | decrease_rate(struct ieee80211_node *ni) 77 | { 78 | ni->ni_txrate--; 79 | } 80 | 81 | void 82 | ieee80211_amrr_node_init(const struct ieee80211_amrr *amrr, 83 | struct ieee80211_amrr_node *amn) 84 | { 85 | amn->amn_success = 0; 86 | amn->amn_recovery = 0; 87 | amn->amn_txcnt = amn->amn_retrycnt = 0; 88 | amn->amn_success_threshold = amrr->amrr_min_success_threshold; 89 | } 90 | 91 | /* 92 | * Update ni->ni_txrate. 93 | */ 94 | void 95 | ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni, 96 | struct ieee80211_amrr_node *amn) 97 | { 98 | #define RV(rate) ((rate) & IEEE80211_RATE_VAL) 99 | int need_change = 0; 100 | 101 | if (is_success(amn) && is_enough(amn)) { 102 | amn->amn_success++; 103 | if (amn->amn_success >= amn->amn_success_threshold && 104 | !is_max_rate(ni)) { 105 | amn->amn_recovery = 1; 106 | amn->amn_success = 0; 107 | increase_rate(ni); 108 | DPRINTF(("increase rate=%d,#tx=%d,#retries=%d\n", 109 | RV(ni->ni_rates.rs_rates[ni->ni_txrate]), 110 | amn->amn_txcnt, amn->amn_retrycnt)); 111 | need_change = 1; 112 | } else { 113 | amn->amn_recovery = 0; 114 | } 115 | } else if (is_failure(amn)) { 116 | amn->amn_success = 0; 117 | if (!is_min_rate(ni)) { 118 | if (amn->amn_recovery) { 119 | amn->amn_success_threshold *= 2; 120 | if (amn->amn_success_threshold > 121 | amrr->amrr_max_success_threshold) 122 | amn->amn_success_threshold = 123 | amrr->amrr_max_success_threshold; 124 | } else { 125 | amn->amn_success_threshold = 126 | amrr->amrr_min_success_threshold; 127 | } 128 | decrease_rate(ni); 129 | DPRINTF(("decrease rate=%d,#tx=%d,#retries=%d\n", 130 | RV(ni->ni_rates.rs_rates[ni->ni_txrate]), 131 | amn->amn_txcnt, amn->amn_retrycnt)); 132 | need_change = 1; 133 | } 134 | amn->amn_recovery = 0; 135 | } 136 | 137 | if (is_enough(amn) || need_change) 138 | reset_cnt(amn); 139 | #undef RV 140 | } 141 | -------------------------------------------------------------------------------- /itl80211/openbsd/net80211/ieee80211_amrr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | /* $OpenBSD: ieee80211_amrr.h,v 1.4 2007/06/16 13:17:05 damien Exp $ */ 15 | 16 | /*- 17 | * Copyright (c) 2006 18 | * Damien Bergamini 19 | * 20 | * Permission to use, copy, modify, and distribute this software for any 21 | * purpose with or without fee is hereby granted, provided that the above 22 | * copyright notice and this permission notice appear in all copies. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 25 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 26 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 27 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 29 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | */ 32 | #ifndef _NET80211_IEEE80211_AMRR_H_ 33 | #define _NET80211_IEEE80211_AMRR_H_ 34 | 35 | /*- 36 | * Naive implementation of the Adaptive Multi Rate Retry algorithm: 37 | * 38 | * "IEEE 802.11 Rate Adaptation: A Practical Approach" 39 | * Mathieu Lacage, Hossein Manshaei, Thierry Turletti 40 | * INRIA Sophia - Projet Planete 41 | * http://www-sop.inria.fr/rapports/sophia/RR-5208.html 42 | */ 43 | 44 | /* 45 | * Rate control settings. 46 | */ 47 | struct ieee80211_amrr { 48 | u_int amrr_min_success_threshold; 49 | u_int amrr_max_success_threshold; 50 | }; 51 | 52 | #define IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD 1 53 | #define IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD 15 54 | 55 | /* 56 | * Rate control state for a given node. 57 | */ 58 | struct ieee80211_amrr_node { 59 | u_int amn_success; 60 | u_int amn_recovery; 61 | u_int amn_success_threshold; 62 | u_int amn_txcnt; 63 | u_int amn_retrycnt; 64 | }; 65 | 66 | void ieee80211_amrr_node_init(const struct ieee80211_amrr *, 67 | struct ieee80211_amrr_node *); 68 | void ieee80211_amrr_choose(struct ieee80211_amrr *, struct ieee80211_node *, 69 | struct ieee80211_amrr_node *); 70 | 71 | #endif /* _NET80211_IEEE80211_AMRR_H_ */ 72 | -------------------------------------------------------------------------------- /itl80211/openbsd/net80211/timeout.c: -------------------------------------------------------------------------------- 1 | // 2 | // timeout.cpp 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/30. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef timeout_cpp 24 | #define timeout_cpp 25 | 26 | #include 27 | #include 28 | 29 | extern IOWorkLoop *_fWorkloop; 30 | extern IOCommandGate *_fCommandGate; 31 | 32 | int splnet() 33 | { 34 | return 1; 35 | } 36 | 37 | void splx(int s) 38 | { 39 | } 40 | 41 | void timeout_set(CTimeout **t, void (*fn)(void *), void *arg) 42 | { 43 | _fCommandGate->runAction(&CTimeout::timeout_set, t, (void*)fn, arg); 44 | } 45 | 46 | int timeout_add_msec(CTimeout **to, int msecs) 47 | { 48 | return _fCommandGate->runAction(&CTimeout::timeout_add_msec, to, _fWorkloop, &msecs) == kIOReturnSuccess ? 1 : 0; 49 | } 50 | 51 | int timeout_add_sec(CTimeout **to, int secs) 52 | { 53 | return timeout_add_msec(to, secs * 1000); 54 | } 55 | 56 | int timeout_add_usec(CTimeout **to, int usecs) 57 | { 58 | return timeout_add_msec(to, (int) usecs / 1000); 59 | } 60 | 61 | int timeout_del(CTimeout **to) 62 | { 63 | // IOLog("timeout_del\n"); 64 | return _fCommandGate->runAction(&CTimeout::timeout_del, to, _fWorkloop) == kIOReturnSuccess ? 1 : 0; 65 | } 66 | 67 | int timeout_free(CTimeout **to) 68 | { 69 | return _fCommandGate->runAction(&CTimeout::timeout_free, to, _fWorkloop) == kIOReturnSuccess ? 1 : 0; 70 | } 71 | 72 | int timeout_pending(CTimeout **to) 73 | { 74 | return _fCommandGate->runAction(&CTimeout::timeout_pending, to) == kIOReturnSuccess ? 1 : 0; 75 | } 76 | 77 | int timeout_initialized(CTimeout **to) 78 | { 79 | return (*to) != NULL; 80 | } 81 | 82 | #endif /* timeout_cpp */ 83 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/CTimeout.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // CTimeout.h 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/30. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef CTimeout_h 24 | #define CTimeout_h 25 | 26 | #include 27 | #include 28 | 29 | class CTimeout : public OSObject { 30 | OSDeclareDefaultStructors(CTimeout) 31 | 32 | public: 33 | static void timeoutOccurred(OSObject* owner, IOTimerEventSource* timer); 34 | 35 | static IOReturn timeout_add_msec(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); 36 | 37 | static IOReturn timeout_del(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); 38 | 39 | static IOReturn timeout_free(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); 40 | 41 | static IOReturn timeout_set(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); 42 | 43 | static IOReturn timeout_pending(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); 44 | 45 | public: 46 | IOTimerEventSource* tm; 47 | void (*to_func)(void *); /* function to call */ 48 | void *to_arg; /* function argument */ 49 | bool isPending; 50 | }; 51 | 52 | #endif /* CTimeout_h */ 53 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_arc4random.h: -------------------------------------------------------------------------------- 1 | // 2 | // _arc4random.h 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/22. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | /* 9 | * Copyright (C) 2020 钟先耀 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | */ 21 | 22 | #ifndef _arc4random_h 23 | #define _arc4random_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | /* Add platform entropy 32 bytes (256 bits) at a time. */ 33 | #define ADD_ENTROPY 32 34 | 35 | /* Re-seed from the platform RNG after generating this many bytes. */ 36 | #define BYTES_BEFORE_RESEED 1600000 37 | 38 | static inline u_int32_t arc4random() 39 | { 40 | u_int32_t r; 41 | read_random(&r, sizeof(r)); 42 | return r; 43 | } 44 | 45 | static inline void arc4random_buf(void *buf, size_t n) 46 | { 47 | read_random(buf, (u_int)n); 48 | } 49 | 50 | static inline u_int32_t arc4random_uniform(u_int32_t upper_bound) 51 | { 52 | u_int32_t r, min; 53 | 54 | if (upper_bound < 2) 55 | return 0; 56 | 57 | /* 2**32 % x == (2**32 - x) % x */ 58 | min = -upper_bound % upper_bound; 59 | 60 | /* 61 | * This could theoretically loop forever but each retry has 62 | * p > 0.5 (worst case, usually far better) of selecting a 63 | * number inside the range we need, so it should rarely need 64 | * to re-roll. 65 | */ 66 | for (;;) { 67 | r = arc4random(); 68 | if (r >= min) 69 | break; 70 | } 71 | 72 | return r % upper_bound; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_buf.h: -------------------------------------------------------------------------------- 1 | // 2 | // _buf.h 3 | // AppleIntelWifiAdapter 4 | // 5 | // Created by 钟先耀 on 2020/1/25. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2020 钟先耀 11 | * 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef _buf_h 24 | #define _buf_h 25 | 26 | /* Macros to clear/set/test flags. */ 27 | #define SET(t, f) (t) |= (f) 28 | #define CLR(t, f) (t) &= ~(f) 29 | #define ISSET(t, f) ((t) & (f)) 30 | 31 | #endif /* _buf_h */ 32 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef _clock_h 16 | #define _clock_h 17 | 18 | #include 19 | 20 | #define hz 100 21 | #define ticks \ 22 | ({ \ 23 | uint64_t t; \ 24 | uint64_t k; \ 25 | clock_get_uptime(&t); \ 26 | absolutetime_to_nanoseconds(t, &k); \ 27 | (int)((k * hz) / 1000000000); \ 28 | }) 29 | 30 | #endif /* _clock_h */ 31 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_ifq.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // _ifq.cpp 3 | // itlwm 4 | // 5 | // Created by zxystd on 2022/8/13. 6 | // Copyright © 2022 钟先耀. All rights reserved. 7 | // 8 | 9 | #include 10 | 11 | void ifq_init(struct _ifqueue *ifq, struct _ifnet *ifp, unsigned int maxLen) 12 | { 13 | if (!ifq->queue) 14 | ifq->queue = IOPacketQueue::withCapacity(maxLen); 15 | else 16 | ifq->queue->setCapacity(maxLen); 17 | ifq->ifq_oactive = 0; 18 | } 19 | 20 | void ifq_destroy(struct _ifqueue *ifq) 21 | { 22 | if (ifq->queue) { 23 | ifq->queue->release(); 24 | ifq->queue = nullptr; 25 | } 26 | } 27 | 28 | void ifq_flush(struct _ifqueue *ifq) 29 | { 30 | if (ifq->queue) 31 | ifq->queue->lockFlush(); 32 | } 33 | 34 | bool ifq_empty(struct _ifqueue *ifq) 35 | { 36 | return ifq->queue->getSize() == 0; 37 | } 38 | 39 | uint32_t ifq_len(struct _ifqueue *ifq) 40 | { 41 | return ifq->queue->getSize(); 42 | } 43 | 44 | void ifq_set_maxlen(struct _ifqueue *ifq, uint32_t maxLen) 45 | { 46 | ifq->queue->setCapacity(maxLen); 47 | } 48 | 49 | void ifq_set_oactive(struct _ifqueue *ifq) 50 | { 51 | ifq->ifq_oactive = 1; 52 | } 53 | 54 | unsigned int ifq_is_oactive(struct _ifqueue *ifq) 55 | { 56 | return ifq->ifq_oactive; 57 | } 58 | 59 | void ifq_clr_oactive(struct _ifqueue *ifq) 60 | { 61 | ifq->ifq_oactive = 0; 62 | } 63 | 64 | mbuf_t ifq_dequeue(struct _ifqueue *ifq) 65 | { 66 | return ifq->queue->lockDequeue(); 67 | } 68 | 69 | int ifq_enqueue(struct _ifqueue *ifq, mbuf_t m) 70 | { 71 | ifq->queue->lockEnqueueWithDrop(m); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_ifq.h: -------------------------------------------------------------------------------- 1 | // 2 | // _ifq.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/3/1. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | /* 9 | * Copyright (C) 2020 钟先耀 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | */ 21 | 22 | #ifndef _ifq_h 23 | #define _ifq_h 24 | #include 25 | #include 26 | 27 | struct _ifqueue { 28 | unsigned int ifq_oactive; 29 | IOPacketQueue *queue; 30 | }; 31 | 32 | void ifq_init(struct _ifqueue *ifq, struct _ifnet *ifp, unsigned int maxLen); 33 | 34 | void ifq_destroy(struct _ifqueue *ifq); 35 | 36 | void ifq_flush(struct _ifqueue *ifq); 37 | 38 | bool ifq_empty(struct _ifqueue *ifq); 39 | 40 | uint32_t ifq_len(struct _ifqueue *ifq); 41 | 42 | void ifq_set_maxlen(struct _ifqueue *ifq, uint32_t maxLen); 43 | 44 | void ifq_set_oactive(struct _ifqueue *ifq); 45 | 46 | unsigned int ifq_is_oactive(struct _ifqueue *ifq); 47 | 48 | void ifq_clr_oactive(struct _ifqueue *ifq); 49 | 50 | mbuf_t ifq_dequeue(struct _ifqueue *ifq); 51 | 52 | int ifq_enqueue(struct _ifqueue *ifq, mbuf_t m); 53 | 54 | #endif /* _ifq_h */ 55 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_malloc.h: -------------------------------------------------------------------------------- 1 | // 2 | // _malloc.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/7/24. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | /* 9 | * Copyright (C) 2020 钟先耀 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | */ 21 | 22 | #ifndef _malloc_h 23 | #define _malloc_h 24 | 25 | #include 26 | 27 | static inline void* 28 | malloc(vm_size_t len, int type, int how) 29 | { 30 | void* addr = IOMalloc(len + sizeof(vm_size_t)); 31 | if (addr == NULL) { 32 | return NULL; 33 | } 34 | *((vm_size_t*) addr) = len; 35 | void *buf = (void*)((uint8_t*)addr + sizeof(vm_size_t)); 36 | bzero(buf, len); 37 | return buf; 38 | } 39 | 40 | static inline void 41 | free(void* addr) 42 | { 43 | if (addr == NULL) { 44 | return; 45 | } 46 | void* actual_addr = (void*)((uint8_t*)addr - sizeof(vm_size_t)); 47 | vm_size_t len = *((vm_size_t*) actual_addr); 48 | IOFree(actual_addr, len + sizeof(vm_size_t)); 49 | } 50 | 51 | #endif /* _malloc_h */ 52 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_mbuf.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // _mbuf.cpp 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/6/14. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | /* 9 | * Copyright (C) 2020 钟先耀 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | */ 21 | 22 | #include 23 | extern "C" { 24 | #include 25 | } 26 | #include 27 | 28 | extern IOCommandGate *_fCommandGate; 29 | 30 | struct network_header { 31 | char pad[0x48]; 32 | }; 33 | 34 | static IOReturn _if_input(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3) 35 | { 36 | mbuf_t m; 37 | bool isEmpty = true; 38 | struct _ifnet *ifq = (struct _ifnet *)arg0; 39 | struct mbuf_list *ml = (struct mbuf_list *)arg1; 40 | 41 | MBUF_LIST_FOREACH(ml, m) { 42 | if (ifq->iface == NULL) { 43 | panic("%s ifq->iface == NULL!!!\n", __FUNCTION__); 44 | break; 45 | } 46 | if (m == NULL) { 47 | XYLog("%s m == NULL!!!\n", __FUNCTION__); 48 | continue; 49 | } 50 | // XYLog("%s %d 啊啊啊啊 ifq->iface->inputPacket(m) hdr_len=%d len=%d\n", __FUNCTION__, __LINE__, mbuf_pkthdr_len(m), mbuf_len(m)); 51 | isEmpty = false; 52 | ifq->iface->inputPacket(m, 0, IONetworkInterface::kInputOptionQueuePacket); 53 | if (ifq->netStat != NULL) { 54 | ifq->netStat->inputPackets++; 55 | } 56 | } 57 | if (!isEmpty) { 58 | ifq->iface->flushInputQueue(); 59 | } 60 | return kIOReturnSuccess; 61 | } 62 | 63 | int if_input(struct _ifnet *ifq, struct mbuf_list *ml) 64 | { 65 | return _fCommandGate->runAction((IOCommandGate::Action)_if_input, ifq, ml); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_null.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: _null.h,v 1.2 2016/09/09 22:07:58 millert Exp $ */ 2 | 3 | /* 4 | * Written by Todd C. Miller, September 9, 2016 5 | * Public domain. 6 | */ 7 | 8 | #ifndef NULL 9 | #if !defined(__cplusplus) 10 | #define NULL ((void *)0) 11 | #elif __cplusplus >= 201103L 12 | #define NULL nullptr 13 | #elif defined(__GNUG__) 14 | #define NULL __null 15 | #else 16 | #define NULL 0L 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/_task.h: -------------------------------------------------------------------------------- 1 | // 2 | // _task.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/3/1. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | /* 9 | * Copyright (C) 2020 钟先耀 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | */ 21 | 22 | #ifndef _task_h 23 | #define _task_h 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | struct task { 31 | TAILQ_ENTRY(task) t_entry; 32 | void (*t_func)(void *); 33 | void *t_arg; 34 | unsigned int t_flags; 35 | char name[256]; 36 | }; 37 | 38 | #define TASK_ONQUEUE 1 39 | #define TASK_BARRIER 2 40 | 41 | TAILQ_HEAD(task_list, task); 42 | 43 | #define TASKQ_MPSAFE (1 << 0) 44 | 45 | #define TASK_INITIALIZER(_f, _a) {{ NULL, NULL }, (_f), (_a), 0 } 46 | 47 | #define task_pending(_t) ((_t)->t_flags & TASK_ONQUEUE) 48 | 49 | extern struct taskq *const systq; 50 | 51 | void taskq_init(); 52 | struct taskq *taskq_create(const char *, unsigned int, int, unsigned int); 53 | void taskq_destroy(struct taskq *); 54 | void taskq_barrier(struct taskq *); 55 | 56 | void taskq_del_barrier(struct taskq *, struct task *); 57 | 58 | void task_set(struct task *, void (*)(void *), void *, const char *); 59 | int task_add(struct taskq *, struct task *); 60 | int task_del(struct taskq *, struct task *); 61 | 62 | #endif /* _task_h */ 63 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/arp.h: -------------------------------------------------------------------------------- 1 | // 2 | // arp.h 3 | // itlwm 4 | // 5 | // Created by zxystd on 2023/7/1. 6 | // Copyright © 2023 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef arp_h 10 | #define arp_h 11 | 12 | #include 13 | 14 | void debug_print_arp(const char *tag, mbuf_t m); 15 | 16 | #endif /* arp_h */ 17 | -------------------------------------------------------------------------------- /itl80211/openbsd/sys/timeout.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) 2020 钟先耀 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | */ 15 | /* $OpenBSD: timeout.h,v 1.29 2019/07/12 00:04:59 cheloha Exp $ */ 16 | /* 17 | * Copyright (c) 2000-2001 Artur Grabowski 18 | * All rights reserved. 19 | * 20 | * Redistribution and use in source and binary forms, with or without 21 | * modification, are permitted provided that the following conditions 22 | * are met: 23 | * 24 | * 1. Redistributions of source code must retain the above copyright 25 | * notice, this list of conditions and the following disclaimer. 26 | * 2. The name of the author may not be used to endorse or promote products 27 | * derived from this software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 30 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 31 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 33 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 34 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 35 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 36 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 37 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 38 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef _SYS_TIMEOUT_H_ 42 | #define _SYS_TIMEOUT_H_ 43 | 44 | 45 | #include 46 | #include 47 | #include /* _Q_INVALIDATE */ 48 | #include 49 | #include 50 | #include 51 | 52 | #define _KERNEL 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | void initTimeout(IOWorkLoop *workloop); 60 | void releaseTimeout(); 61 | int splnet(); 62 | void splx(int s); 63 | void timeout_set(CTimeout **t, void (*fn)(void *), void *arg); 64 | int timeout_add_msec(CTimeout **to, int msecs); 65 | int timeout_add_sec(CTimeout **to, int secs); 66 | int timeout_add_usec(CTimeout **to, int usecs); 67 | int timeout_del(CTimeout **to); 68 | int timeout_pending(CTimeout **to); 69 | int timeout_free(CTimeout **to); 70 | 71 | int timeout_initialized(CTimeout **to); 72 | 73 | #endif /* _SYS_TIMEOUT_H_ */ 74 | -------------------------------------------------------------------------------- /itl80211/zutil.c: -------------------------------------------------------------------------------- 1 | // 2 | // zutil.c 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/9/4. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #include 10 | extern "C" { 11 | typedef struct z_mem 12 | { 13 | UInt32 alloc_size; 14 | UInt8 data[0]; 15 | } z_mem; 16 | 17 | void *zcalloc(void *opaque, uint items, uint size) 18 | { 19 | void* result = NULL; 20 | z_mem* zmem = NULL; 21 | UInt32 allocSize = items * size + sizeof(zmem); 22 | 23 | zmem = (z_mem*)IOMalloc(allocSize); 24 | 25 | if (zmem) 26 | { 27 | zmem->alloc_size = allocSize; 28 | result = (void*)&(zmem->data); 29 | } 30 | 31 | return result; 32 | } 33 | 34 | void zcfree(void *opaque, void *ptr) 35 | { 36 | UInt32* skipper = (UInt32 *)ptr - 1; 37 | z_mem* zmem = (z_mem*)skipper; 38 | IOFree((void*)zmem, zmem->alloc_size); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /itl80211/zutil.h: -------------------------------------------------------------------------------- 1 | // 2 | // zutil.h 3 | // itlwm 4 | // 5 | // Created by qcwap on 2020/9/4. 6 | // Copyright © 2020 钟先耀. All rights reserved. 7 | // 8 | 9 | #ifndef zutil_h 10 | #define zutil_h 11 | 12 | #include 13 | #include 14 | 15 | extern "C" { 16 | void *zcalloc(void *opaque, uint items, uint size); 17 | 18 | void zcfree(void *opaque, void *ptr); 19 | } 20 | 21 | #endif /* zutil_h */ 22 | -------------------------------------------------------------------------------- /itlwm.xcodeproj/xcshareddata/xcschemes/itlwm.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /itlwm/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MODULE_VERSION) 19 | CFBundleVersion 20 | $(MODULE_VERSION) 21 | IOKitPersonalities 22 | 23 | itlwm 24 | 25 | CFBundleIdentifier 26 | com.zxystd.itlwm 27 | IOClass 28 | itlwm 29 | IOMatchCategory 30 | IODefaultMatchCategory 31 | IOPCIPrimaryMatch 32 | 0x00008086&0x0000ffff 33 | IOProbeScore 34 | 2000 35 | IOProviderClass 36 | IOPCIDevice 37 | IOUserClientClass 38 | ItlNetworkUserClient 39 | WiFiConfig 40 | 41 | WiFi_1 42 | 43 | password 44 | zxyssdt112233 45 | ssid 46 | ssdt 47 | 48 | WiFi_2 49 | 50 | password 51 | zxyssdt112233 52 | ssid 53 | ssdt_5G 54 | 55 | WiFi_3 56 | 57 | password 58 | 59 | ssid 60 | Redmi 61 | 62 | WiFi_4 63 | 64 | password 65 | 9utc5c5f 66 | ssid 67 | CMCC-KtG6 68 | 69 | 70 | 71 | 72 | NSHumanReadableCopyright 73 | Copyright © 2020 钟先耀. All rights reserved. 74 | OSBundleLibraries 75 | 76 | com.apple.iokit.IONetworkingFamily 77 | 1.5.0 78 | com.apple.iokit.IOPCIFamily 79 | 1.7 80 | com.apple.kpi.bsd 81 | 8.10.0 82 | com.apple.kpi.iokit 83 | 8.10.0 84 | com.apple.kpi.libkern 85 | 8.10.0 86 | com.apple.kpi.mach 87 | 8.10.0 88 | 89 | OSBundleRequired 90 | Network-Root 91 | 92 | 93 | -------------------------------------------------------------------------------- /itlwm/ItlNetworkUserClient.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #ifndef ItlNetworkUserClient_hpp 16 | #define ItlNetworkUserClient_hpp 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "itlwm.hpp" 23 | #include 24 | 25 | typedef IOReturn (*IOControlMethodAction)(OSObject * target, void *data, bool isSet); 26 | 27 | class ItlNetworkUserClient : public IOUserClient { 28 | 29 | OSDeclareDefaultStructors( ItlNetworkUserClient ); 30 | 31 | public: 32 | 33 | virtual bool start( IOService * provider ) override; 34 | virtual void stop( IOService * provider ) override; 35 | virtual bool initWithTask( task_t owningTask, void * securityID, 36 | UInt32 type, OSDictionary * properties ) override; 37 | virtual IOReturn clientDied (void) override; 38 | virtual IOReturn clientClose( void ) override; 39 | virtual IOReturn externalMethod( uint32_t selector, IOExternalMethodArguments * arguments, IOExternalMethodDispatch * dispatch = 0, OSObject * target = 0, void * reference = 0 ) override; 40 | 41 | private: 42 | static IOReturn sDRIVER_INFO(OSObject* target, void* data, bool isSet); 43 | static IOReturn sSTA_INFO(OSObject* target, void* data, bool isSet); 44 | static IOReturn sPOWER(OSObject* target, void* data, bool isSet); 45 | static IOReturn sSTATE(OSObject* target, void* data, bool isSet); 46 | static IOReturn sNW_ID(OSObject* target, void* data, bool isSet); 47 | static IOReturn sWPA_KEY(OSObject* target, void* data, bool isSet); 48 | static IOReturn sASSOCIATE(OSObject* target, void* data, bool isSet); 49 | static IOReturn sDISASSOCIATE(OSObject* target, void* data, bool isSet); 50 | static IOReturn sJOIN(OSObject* target, void* data, bool isSet); 51 | static IOReturn sSCAN(OSObject* target, void* data, bool isSet); 52 | static IOReturn sSCAN_RESULT(OSObject* target, void* data, bool isSet); 53 | static IOReturn sTX_POWER_LEVEL(OSObject* target, void* data, bool isSet); 54 | static IOReturn sNW_BSSID(OSObject* target, void* data, bool isSet); 55 | static const IOControlMethodAction sMethods[IOCTL_ID_MAX]; 56 | 57 | private: 58 | task_t fTask; 59 | itlwm *fDriver; 60 | IOEthernetInterface *fInf; 61 | struct _ifnet *fIfp; 62 | ItlDriverController *fDriverController; 63 | ItlDriverInfo *fDriverInfo; 64 | 65 | protected: 66 | bool fScanResultWrapping; 67 | ieee80211_node *fNextNodeToSend; 68 | }; 69 | 70 | 71 | #endif /* ItlNetworkUserClient_hpp */ 72 | -------------------------------------------------------------------------------- /itlwm/PrivateSPI.pch: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #ifdef __PRIVATE_SPI__ 5 | typedef u_int32_t ifnet_ctl_cmd_t; 6 | #endif 7 | 8 | #ifndef __MAC_12_0 9 | #define __MAC_12_0 120000 10 | #endif 11 | 12 | #ifndef __MAC_13_0 13 | #define __MAC_13_0 130000 14 | #endif 15 | 16 | #ifndef __MAC_14_0 17 | #define __MAC_14_0 140000 18 | #endif 19 | 20 | #ifndef __MAC_14_4 21 | #define __MAC_14_4 140400 22 | #endif 23 | -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-Qu-b0-hr-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-Qu-b0-hr-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-Qu-b0-jf-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-Qu-b0-jf-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-Qu-c0-hr-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-Qu-c0-hr-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-Qu-c0-jf-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-Qu-c0-jf-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-QuZ-a0-hr-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-QuZ-a0-hr-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-QuZ-a0-jf-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-QuZ-a0-jf-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-cc-a0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-cc-a0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-gf-a0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-gf-a0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-gf-a0.pnvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-gf-a0.pnvm -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-gf4-a0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-gf4-a0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-gf4-a0.pnvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-gf4-a0.pnvm -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-hr-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-hr-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-so-a0-jf-b0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-so-a0-jf-b0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-ty-a0-gf-a0-68.ucode: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-ty-a0-gf-a0-68.ucode -------------------------------------------------------------------------------- /itlwm/firmware/iwlwifi-ty-a0-gf-a0.pnvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwlwifi-ty-a0-gf-a0.pnvm -------------------------------------------------------------------------------- /itlwm/firmware/iwm-3160-17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-3160-17 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-3168-29: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-3168-29 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-7260-17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-7260-17 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-7265-17: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-7265-17 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-8000C-36: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-8000C-36 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-8265-36: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-8265-36 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-9000-46: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-9000-46 -------------------------------------------------------------------------------- /itlwm/firmware/iwm-9260-46: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwm-9260-46 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-1000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-1000 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-105: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-105 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-135: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-135 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-2000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-2000 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-2030: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-2030 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-4965: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-4965 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-5000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-5000 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-5150: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-5150 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-6000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-6000 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-6005: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-6005 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-6030: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-6030 -------------------------------------------------------------------------------- /itlwm/firmware/iwn-6050: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIntelWireless/itlwm/53c51c2cdd6e4b69beb91f310d74c53422b0f8bd/itlwm/firmware/iwn-6050 -------------------------------------------------------------------------------- /itlwm/hal_iwm/coex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 15 | /* 16 | * Copyright (C) 2013-2014, 2018-2020 Intel Corporation 17 | * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 18 | */ 19 | 20 | #include "ItlIwm.hpp" 21 | 22 | #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) 23 | #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200) 24 | 25 | uint16_t ItlIwm:: 26 | iwm_coex_agg_time_limit(struct iwm_softc *sc, struct ieee80211_node *ni) 27 | { 28 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; 29 | } 30 | 31 | uint8_t ItlIwm:: 32 | iwm_coex_tx_prio(struct iwm_softc *sc, struct ieee80211_frame *wh, uint8_t ac) 33 | { 34 | uint8_t type, subtype; 35 | struct ieee80211com *ic = &sc->sc_ic; 36 | struct ieee80211_node *ni = ic->ic_bss; 37 | bool mplut_enabled = isset(sc->sc_enabled_capa, IWM_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT); 38 | 39 | if (!ni || !ni->ni_chan) 40 | return 0; 41 | 42 | if (!IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) 43 | return 0; 44 | 45 | type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 46 | subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 47 | 48 | if (type == IEEE80211_FC0_TYPE_DATA) { 49 | if (ieee80211_has_qos(wh)) { 50 | switch (ac) { 51 | case EDCA_AC_BE: 52 | return mplut_enabled ? 1 : 0; 53 | case EDCA_AC_VI: 54 | return mplut_enabled ? 2 : 3; 55 | case EDCA_AC_VO: 56 | return 3; 57 | default: 58 | return 0; 59 | } 60 | } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) 61 | return 3; 62 | else 63 | return 0; 64 | } else if (type == IEEE80211_FC0_TYPE_MGT) 65 | return subtype == IEEE80211_FC0_SUBTYPE_DISASSOC ? 0 : 3; 66 | else if (type == IEEE80211_FC0_TYPE_CTL) 67 | /* ignore cfend and cfendack frames as we never send those */ 68 | return 3; 69 | 70 | return 0; 71 | } 72 | 73 | bool ItlIwm:: 74 | iwm_coex_is_ant_avail(struct iwm_softc *sc, u8 ant) 75 | { 76 | #if 0 77 | /* there is no other antenna, shared antenna is always available */ 78 | if (mvm->cfg->bt_shared_single_ant) 79 | return true; 80 | #endif 81 | 82 | if (ant & sc->non_shared_ant) 83 | return true; 84 | 85 | #ifdef notyet_coex 86 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < 87 | BT_HIGH_TRAFFIC; 88 | #else 89 | return true; 90 | #endif 91 | } 92 | 93 | bool ItlIwm:: 94 | iwm_coex_is_mimo_allowed(struct iwm_softc *sc, struct ieee80211_node *ni) 95 | { 96 | #ifdef notyet_coex 97 | struct iwm_node *in = (struct iwm_node *)ni; 98 | struct iwm_phy_ctxt *phy_ctxt = in->in_phyctxt; 99 | enum iwl_bt_coex_lut_type lut_type; 100 | 101 | if (sc->last_bt_notif.ttc_status & BIT(phy_ctxt->id)) 102 | return true; 103 | 104 | if (le32_to_cpu(sc->last_bt_notif.bt_activity_grading) < 105 | BT_HIGH_TRAFFIC) 106 | return true; 107 | 108 | /* 109 | * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas 110 | * since BT is already killed. 111 | * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while 112 | * we Tx. 113 | * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO. 114 | */ 115 | lut_type = iwl_get_coex_type(mvm, mvmsta->vif); 116 | return lut_type != BT_COEX_LOOSE_LUT; 117 | #else 118 | return true; 119 | #endif 120 | } 121 | 122 | bool ItlIwm:: 123 | iwm_coex_is_tpc_allowed(struct iwm_softc *mvm, bool is5G) 124 | { 125 | if (is5G) 126 | return false; 127 | 128 | #ifdef notyet_coex 129 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) >= BT_LOW_TRAFFIC; 130 | #else 131 | return false; 132 | #endif 133 | } 134 | 135 | bool ItlIwm:: 136 | iwm_coex_is_shared_ant_avail(struct iwm_softc *mvm) 137 | { 138 | #ifdef notyet_coex 139 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < BT_HIGH_TRAFFIC; 140 | #else 141 | return mvm->sc_device_family == IWM_DEVICE_FAMILY_9000 && 142 | (iwm_fw_valid_tx_ant(mvm) & IWM_ANT_B); 143 | #endif 144 | } 145 | -------------------------------------------------------------------------------- /itlwm/pm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 钟先耀 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | */ 14 | 15 | #include "itlwm.hpp" 16 | 17 | static IOPMPowerState powerStateArray[kPowerStateCount] = 18 | { 19 | {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 20 | {1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0} 21 | }; 22 | 23 | void itlwm::unregistPM() 24 | { 25 | if (powerOffThreadCall) { 26 | thread_call_free(powerOffThreadCall); 27 | powerOffThreadCall = NULL; 28 | } 29 | if (powerOnThreadCall) { 30 | thread_call_free(powerOnThreadCall); 31 | powerOnThreadCall = NULL; 32 | } 33 | } 34 | 35 | IOReturn itlwm::setPowerState(unsigned long powerStateOrdinal, IOService *policyMaker) 36 | { 37 | IOReturn result = IOPMAckImplied; 38 | 39 | if (pmPowerState == powerStateOrdinal) { 40 | return result; 41 | } 42 | switch (powerStateOrdinal) { 43 | case kPowerStateOff: 44 | if (powerOffThreadCall) { 45 | retain(); 46 | if (thread_call_enter(powerOffThreadCall)) { 47 | release(); 48 | } 49 | result = 5000000; 50 | } 51 | break; 52 | case kPowerStateOn: 53 | if (powerOnThreadCall) { 54 | retain(); 55 | if (thread_call_enter(powerOnThreadCall)) { 56 | release(); 57 | } 58 | result = 5000000; 59 | } 60 | break; 61 | 62 | default: 63 | break; 64 | } 65 | return result; 66 | } 67 | 68 | IOReturn itlwm::setWakeOnMagicPacket(bool active) 69 | { 70 | magicPacketEnabled = active; 71 | return kIOReturnSuccess; 72 | } 73 | 74 | static void handleSetPowerStateOff(thread_call_param_t param0, 75 | thread_call_param_t param1) 76 | { 77 | itlwm *self = (itlwm *)param0; 78 | 79 | if (param1 == 0) 80 | { 81 | self->getCommandGate()->runAction((IOCommandGate::Action) 82 | handleSetPowerStateOff, 83 | (void *) 1); 84 | } 85 | else 86 | { 87 | self->setPowerStateOff(); 88 | self->release(); 89 | } 90 | } 91 | 92 | static void handleSetPowerStateOn(thread_call_param_t param0, 93 | thread_call_param_t param1) 94 | { 95 | itlwm *self = (itlwm *) param0; 96 | 97 | if (param1 == 0) 98 | { 99 | self->getCommandGate()->runAction((IOCommandGate::Action) 100 | handleSetPowerStateOn, 101 | (void *) 1); 102 | } 103 | else 104 | { 105 | self->setPowerStateOn(); 106 | self->release(); 107 | } 108 | } 109 | 110 | IOReturn itlwm::registerWithPolicyMaker(IOService *policyMaker) 111 | { 112 | IOReturn ret; 113 | 114 | pmPowerState = kPowerStateOn; 115 | pmPolicyMaker = policyMaker; 116 | 117 | powerOffThreadCall = thread_call_allocate( 118 | (thread_call_func_t)handleSetPowerStateOff, 119 | (thread_call_param_t)this); 120 | powerOnThreadCall = thread_call_allocate( 121 | (thread_call_func_t)handleSetPowerStateOn, 122 | (thread_call_param_t)this); 123 | ret = pmPolicyMaker->registerPowerDriver(this, 124 | powerStateArray, 125 | kPowerStateCount); 126 | return ret; 127 | } 128 | 129 | void itlwm::setPowerStateOff() 130 | { 131 | pmPowerState = kPowerStateOff; 132 | pmPolicyMaker->acknowledgeSetPowerState(); 133 | } 134 | 135 | void itlwm::setPowerStateOn() 136 | { 137 | pmPowerState = kPowerStateOn; 138 | pmPolicyMaker->acknowledgeSetPowerState(); 139 | } 140 | -------------------------------------------------------------------------------- /iwlwifi-firmware-license: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2021, Intel Corporation. 2 | All rights reserved. 3 | 4 | Redistribution. Redistribution and use in binary form, without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions must reproduce the above copyright notice and the 9 | following disclaimer in the documentation and/or other materials 10 | provided with the distribution. 11 | * Neither the name of Intel Corporation nor the names of its suppliers 12 | may be used to endorse or promote products derived from this software 13 | without specific prior written permission. 14 | * No reverse engineering, decompilation, or disassembly of this software 15 | is permitted. 16 | 17 | Limited patent license. Intel Corporation grants a world-wide, 18 | royalty-free, non-exclusive license under patents it now or hereafter 19 | owns or controls to make, have made, use, import, offer to sell and 20 | sell ("Utilize") this software, but solely to the extent that any 21 | such patent is necessary to Utilize the software alone, or in 22 | combination with an operating system licensed under an approved Open 23 | Source license as listed by the Open Source Initiative at 24 | http://opensource.org/licenses. The patent license shall not apply to 25 | any other combinations which include this software. No hardware per 26 | se is licensed hereunder. 27 | 28 | DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 29 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 30 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 32 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 33 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 34 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 35 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 37 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 38 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 39 | DAMAGE. 40 | -------------------------------------------------------------------------------- /scripts/fw_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # fw_gen.sh 4 | # itlwm 5 | # 6 | # Created by qcwap on 2020/3/10. 7 | # Copyright © 2020 钟先耀. All rights reserved. 8 | target_file="${PROJECT_DIR}/include/FwBinary.cpp" 9 | if [ -f "$target_file" ]; then 10 | exit 0 11 | fi 12 | while [ $# -gt 0 ]; 13 | do 14 | case $1 in 15 | -P) fw_files=$2 16 | shift 17 | ;; 18 | 19 | esac 20 | shift 21 | done 22 | 23 | script_file="${PROJECT_DIR}/scripts/zlib_compress_fw.py" 24 | python3 "${script_file}" "${target_file}" "${fw_files}" 25 | -------------------------------------------------------------------------------- /scripts/load.sh: -------------------------------------------------------------------------------- 1 | sudo kextunload -b com.zxystd.itlwm 2 | sudo chown -R root:wheel ./../Build/Products/Debug/itlwm.kext 3 | sudo kextutil -v 6 ./../Build/Products/Debug/itlwm.kext 4 | 5 | -------------------------------------------------------------------------------- /scripts/unload.sh: -------------------------------------------------------------------------------- 1 | sudo kextunload ../Build/Products/Debug/itlwm.kext 2 | sudo kextunload -b com.zxystd.itlwm 3 | -------------------------------------------------------------------------------- /scripts/zlib_compress_fw.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # zlib_compress_fw.py 4 | # 5 | # Created by qcwap on 2020/9/3. 6 | # Copyright © 2020 钟先耀. All rights reserved. 7 | 8 | import zlib 9 | import os 10 | import struct 11 | import sys 12 | 13 | copyright = ''' 14 | // itlwm 15 | // 16 | // Copyright © 2020 钟先耀. All rights reserved. 17 | #include "FwData.h" 18 | ''' 19 | 20 | def compress(data): 21 | return zlib.compress(data) 22 | 23 | def format_file_name(file_name): 24 | return file_name.replace(".", "_").replace("-", "_") 25 | 26 | def write_single_file(target_file, path, file): 27 | src_file = open(path, "rb") 28 | src_data = src_file.read() 29 | src_data = compress(src_data) 30 | src_len = len(src_data) 31 | 32 | fw_var_name = format_file_name(file) 33 | target_file.write("\nconst unsigned char ") 34 | target_file.write(fw_var_name) 35 | target_file.write("[] = {") 36 | index = 0; 37 | block = [] 38 | while True: 39 | if index + 16 >= src_len: 40 | block = src_data[index:] 41 | else: 42 | block = src_data[index:index + 16] 43 | index += 16; 44 | if len(block) < 16: 45 | if len(block): 46 | for b in block: 47 | if type(b) is str: 48 | b = ord(b) 49 | target_file.write("0x{:02X}, ".format(b)) 50 | target_file.write("\n") 51 | break 52 | target_file.write("0x{:02X}, 0x{:02X}, 0x{:02X}, 0x{:02X}, " 53 | "0x{:02X}, 0x{:02X}, 0x{:02X}, 0x{:02X}, " 54 | "0x{:02X}, 0x{:02X}, 0x{:02X}, 0x{:02X}, " 55 | "0x{:02X}, 0x{:02X}, 0x{:02X}, 0x{:02X},\n" 56 | .format(*struct.unpack("BBBBBBBBBBBBBBBB", block))) 57 | target_file.write("};\n") 58 | target_file.write("const long int ") 59 | target_file.write(fw_var_name) 60 | target_file.write("_size = sizeof(") 61 | target_file.write(fw_var_name) 62 | target_file.write(");\n") 63 | src_file.close() 64 | 65 | 66 | def process_files(target_file, dir): 67 | if not os.path.exists(target_file): 68 | if not os.path.exists(os.path.dirname(target_file)): 69 | os.mkdirs(os.path.dirname(target_file)) 70 | target_file_handle = open(target_file, "w") 71 | target_file_handle.write(copyright) 72 | for root, dirs, files in os.walk(dir): 73 | for file in files: 74 | path = os.path.join(root, file) 75 | write_single_file(target_file_handle, path, file) 76 | 77 | target_file_handle.write("\n") 78 | target_file_handle.write("const struct FwDesc fwList[] = {") 79 | 80 | for file in files: 81 | target_file_handle.write('{IWL_FW("') 82 | target_file_handle.write(file) 83 | target_file_handle.write('", ') 84 | fw_var_name = format_file_name(file) 85 | target_file_handle.write(fw_var_name) 86 | target_file_handle.write(", ") 87 | target_file_handle.write(fw_var_name) 88 | target_file_handle.write("_size)},\n") 89 | 90 | target_file_handle.write("};\n") 91 | target_file_handle.write("const int fwNumber = ") 92 | target_file_handle.write(str(len(files))) 93 | target_file_handle.write(";\n") 94 | 95 | target_file_handle.close() 96 | 97 | if __name__ == '__main__': 98 | process_files(sys.argv[1], sys.argv[2]) 99 | --------------------------------------------------------------------------------