Skip to content

Commit

Permalink
XNU & IOKit Skywalk Headers (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieJiangXXX committed Jun 5, 2022
1 parent 7905d18 commit 8104e67
Show file tree
Hide file tree
Showing 59 changed files with 20,863 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Headers/IOKit/skywalk/IOSkywalkCloneableNetworkPacket.h
@@ -0,0 +1,76 @@
/*
* Released under "The BSD 3-Clause License"
*
* Copyright (c) 2021 cjiang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef _IOSKYWALKCLONEABLENETWORKPACKET_H
#define _IOSKYWALKCLONEABLENETWORKPACKET_H

#include <IOKit/skywalk/IOSkywalkNetworkPacket.h>

class IOSkywalkCloneableNetworkPacket : public IOSkywalkNetworkPacket
{
OSDeclareDefaultStructors( IOSkywalkCloneableNetworkPacket )

public:
static IOSkywalkPacket * withPool( IOSkywalkPacketBufferPool * pool, IOSkywalkPacketDescriptor * desc, IOOptionBits options );
virtual bool initWithPool( IOSkywalkPacketBufferPool * pool, IOSkywalkPacketDescriptor * desc, IOOptionBits options ) APPLE_KEXT_OVERRIDE;
virtual void free() APPLE_KEXT_OVERRIDE;

IOSkywalkCloneableNetworkPacket * packetClone();
IOReturn packetCloneWithBaseAndLimit( int64_t base, size_t limit, IOSkywalkCloneableNetworkPacket ** packet );
IOReturn setPacketBufferBaseAndLimit( int64_t base, size_t limit );
IOReturn getPacketBufferBaseAddr( uint8_t ** baseAddr );
IOReturn getPacketBufferObjectBaseAddr( uint8_t ** baseAddr );
IOReturn getPacketBufferObjectIOBusBaseAddr( uint8_t ** baseAddr );

virtual bool getPacketBuffers( IOSkywalkPacketBuffer ** buffers, UInt32 count );
virtual UInt32 getPacketBufferCount();
virtual IOMemoryDescriptor * getMemoryDescriptor();
virtual IOReturn setDataLength( UInt32 length ) APPLE_KEXT_OVERRIDE;
virtual UInt32 getDataLength() APPLE_KEXT_OVERRIDE;
virtual IOReturn setDataOffset( UInt16 offset ) APPLE_KEXT_OVERRIDE;
virtual UInt16 getDataOffset() APPLE_KEXT_OVERRIDE;
virtual IOReturn setDataOffsetAndLength( UInt16 offset, UInt32 length ) APPLE_KEXT_OVERRIDE;

virtual IOReturn prepareWithQueue( IOSkywalkPacketQueue * queue, IOSkywalkPacketDirection direction = kIOSkywalkPacketDirectionNone, IOOptionBits options = 0 ) APPLE_KEXT_OVERRIDE;
virtual IOReturn completeWithQueue( IOSkywalkPacketQueue * queue, IOSkywalkPacketDirection direction = kIOSkywalkPacketDirectionNone, IOOptionBits options = 0 ) APPLE_KEXT_OVERRIDE;

virtual UInt32 getPacketType() APPLE_KEXT_OVERRIDE;
virtual kern_buflet_t acquireWithPacketHandle( UInt64 handle, IOOptionBits options ) APPLE_KEXT_OVERRIDE;
virtual void disposePacket() APPLE_KEXT_OVERRIDE;
void printPacket();

protected:
uint64_t _reserved[3]; // 128... I bet they are used or set in another class!
};

#endif
59 changes: 59 additions & 0 deletions Headers/IOKit/skywalk/IOSkywalkController.h
@@ -0,0 +1,59 @@
/*
* Released under "The BSD 3-Clause License"
*
* Copyright (c) 2021 cjiang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef _IOSKYWALKCONTROLLER_H
#define _IOSKYWALKCONTROLLER_H

#include <IOKit/IOService.h>

class IOSkywalkInterface;

class IOSkywalkController : public IOService
{
OSDeclareDefaultStructors( IOSkywalkController )

public:
virtual void free() APPLE_KEXT_OVERRIDE;
virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual bool handleOpen( IOService * forClient, IOOptionBits options, void * arg ) APPLE_KEXT_OVERRIDE;
virtual void handleClose( IOService * forClient, IOOptionBits options ) APPLE_KEXT_OVERRIDE;
virtual bool handleIsOpen( const IOService * forClient ) const APPLE_KEXT_OVERRIDE;
IOReturn attachInterface( IOSkywalkInterface * interface, IOOptionBits options );
IOReturn detachInterface( IOSkywalkInterface * interface, IOOptionBits options );

protected:
void * mReserved;
OSSet * mInterfaces;
};

#endif
95 changes: 95 additions & 0 deletions Headers/IOKit/skywalk/IOSkywalkEthernetInterface.h
@@ -0,0 +1,95 @@
/*
* Released under "The BSD 3-Clause License"
*
* Copyright (c) 2021 cjiang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef _IOSKYWALKETHERNETINTERFACE_H
#define _IOSKYWALKETHERNETINTERFACE_H

#include <IOKit/skywalk/IOSkywalkNetworkInterface.h>
#include <net/if_dl.h>

class IOSkywalkEthernetInterface : public IOSkywalkNetworkInterface
{
OSDeclareAbstractStructors( IOSkywalkEthernetInterface )

struct RegistrationInfo;

public:
virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual void free() APPLE_KEXT_OVERRIDE;

bool initRegistrationInfo( RegistrationInfo * info, IOOptionBits options, size_t size );
IOReturn registerEthernetInterface( const RegistrationInfo * info, IOSkywalkPacketQueue ** queues, IOOptionBits queueOptions, IOSkywalkPacketBufferPool * pool1, IOSkywalkPacketBufferPool * pool2, IOOptionBits options = 0 );
IOReturn deregisterEthernetInterface( IOOptionBits options = 0 );

virtual IOReturn initBSDInterfaceParameters( struct ifnet_init_eparams * params, sockaddr_dl ** ll ) APPLE_KEXT_OVERRIDE;
virtual IOReturn prepareBSDInterface( ifnet_t interface, IOOptionBits options ) APPLE_KEXT_OVERRIDE;
virtual errno_t processBSDCommand( ifnet_t interface, UInt32 cmd, void * data ) APPLE_KEXT_OVERRIDE;

errno_t ioctl_sifflags( ifnet_t interface );
errno_t ioctl_multicast( ifnet_t interface, bool );

virtual IOReturn getPacketTapInfo(UInt32 *, UInt32 *) APPLE_KEXT_OVERRIDE;
virtual UInt32 getMaxTransferUnit() APPLE_KEXT_OVERRIDE;
virtual UInt32 getMinPacketSize() APPLE_KEXT_OVERRIDE;
virtual UInt32 getHardwareAssists() APPLE_KEXT_OVERRIDE;

virtual IOReturn configureMulticastFilter( UInt32, const ether_addr * addresses, uint32_t count );
virtual IOReturn setPromiscuousModeEnable( bool enable, IOOptionBits options );

OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 0 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 1 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 2 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 3 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 4 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 5 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 6 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 7 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 8 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 9 );
OSMetaClassDeclareReservedUnused( IOSkywalkEthernetInterface, 10 );

protected:
void * mReserved;

struct ExpansionData
{
RegistrationInfo * eRegistrationInfo;
OSData * eMulticastAddresses;
UInt32 eNumMulticastAddresses;
UInt16 eBSDInterfaceFlags;
sockaddr_dl eLinkLayerSockAddress;
};
ExpansionData * mExpansionData;
};

#endif
49 changes: 49 additions & 0 deletions Headers/IOKit/skywalk/IOSkywalkFamily.h
@@ -0,0 +1,49 @@
/*
* Released under "The BSD 3-Clause License"
*
* Copyright (c) 2021 cjiang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#pragma once

#include <IOKit/skywalk/IOSkywalkSupport.h>
#include <IOKit/skywalk/IOSkywalkTypes.h>
#include <IOKit/skywalk/IOSkywalkMemorySegment.h>
#include <IOKit/skywalk/IOSkywalkPacket.h>
#include <IOKit/skywalk/IOSkywalkNetworkPacket.h>
#include <IOKit/skywalk/IOSkywalkCloneableNetworkPacket.h>
#include <IOKit/skywalk/IOSkywalkPacketBuffer.h>
#include <IOKit/skywalk/IOSkywalkPacketBufferPool.h>
#include <IOKit/skywalk/IOSkywalkPacketQueue.h>
#include <IOKit/skywalk/IOSkywalkController.h>
#include <IOKit/skywalk/IOSkywalkNetworkController.h>
#include <IOKit/skywalk/IOSkywalkInterface.h>
#include <IOKit/skywalk/IOSkywalkNetworkInterface.h>
#include <IOKit/skywalk/IOSkywalkEthernetInterface.h>
81 changes: 81 additions & 0 deletions Headers/IOKit/skywalk/IOSkywalkInterface.h
@@ -0,0 +1,81 @@
/*
* Released under "The BSD 3-Clause License"
*
* Copyright (c) 2021 cjiang. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef _IOSKYWALKINTERFACE_H
#define _IOSKYWALKINTERFACE_H

#include <IOKit/IOService.h>

class IOSkywalkPacketQueue;
class IOSkywalkPacketBufferPool;

class IOSkywalkInterface : public IOService
{
OSDeclareAbstractStructors( IOSkywalkInterface )

protected:
virtual void free() APPLE_KEXT_OVERRIDE;
virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual void stop( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual bool handleOpen( IOService * forClient, IOOptionBits options, void * arg ) APPLE_KEXT_OVERRIDE;
virtual void handleClose( IOService * forClient, IOOptionBits options ) APPLE_KEXT_OVERRIDE;
virtual bool handleIsOpen( const IOService * forClient ) const APPLE_KEXT_OVERRIDE;
virtual IOReturn enable( IOOptionBits options ) = 0;
virtual IOReturn disable( IOOptionBits options ) = 0;
virtual IOReturn clientConnectWithTask( task_t task, IOService * forClient, IOOptionBits options );
virtual void clientDisconnect( IOService * forClient, IOOptionBits options );

IOReturn registerInterfaceWithQueues( IOSkywalkPacketQueue ** queue, UInt32 count, IOSkywalkPacketBufferPool * pool1, IOSkywalkPacketBufferPool * pool2, IOOptionBits options = 0 );
IOReturn deregisterInterfaceWithQueues();

OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 0 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 1 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 2 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 3 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 4 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 5 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 6 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 7 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 8 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 9 );
OSMetaClassDeclareReservedUnused( IOSkywalkInterface, 10 );

protected:
void * mReserved; // 136
OSArray * mPacketQueueArray; // 144
IOSkywalkPacketBufferPool * mPacketBufferPool1; // 152
IOSkywalkPacketBufferPool * mPacketBufferPool2; // 160
OSSet * mClients; // 168
};

#endif

0 comments on commit 8104e67

Please sign in to comment.