# SPDX-License-Identifier: GPL-2.0-only
# This file is part of Scapy RPC
# See https://scapy.net/ for more information
# Copyright (C) Gabriel Potter

# [ms-tpmvsc] v8.0 (Tue, 23 Apr 2024)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- ITpmVirtualSmartCardManagerStatusCallback (v0.0): 1A1BB35F-ABB8-451C-A1AE-33D98F1BEF4A
- ITpmVirtualSmartCardManager (v0.0): 112B1DFF-D9DC-41F7-869F-D67FEE7CB591
- ITpmVirtualSmartCardManager2 (v0.0): FDF8A2B9-02DE-47F4-BC26-AA85AB5E5267
- ITpmVirtualSmartCardManager3 (v0.0): 3C745A97-F375-4150-BE17-5950F694C699
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid


from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfStrLenField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntEnumField,
    NDRIntField,
    NDRPacketField,
    NDRSignedIntField,
    register_com_interface,
)

IUNKNOWN_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire
}
register_com_interface(
    name="IUnknown",
    uuid=uuid.UUID("00000000-0000-0000-C000-000000000046"),
    opnums=IUNKNOWN_OPNUMS,
)


class TPMVSCMGR_STATUS(IntEnum):
    TPMVSCMGR_STATUS_VTPMSMARTCARD_INITIALIZING = 1
    TPMVSCMGR_STATUS_VTPMSMARTCARD_CREATING = 2
    TPMVSCMGR_STATUS_VTPMSMARTCARD_DESTROYING = 3
    TPMVSCMGR_STATUS_VGIDSSIMULATOR_INITIALIZING = 4
    TPMVSCMGR_STATUS_VGIDSSIMULATOR_CREATING = 5
    TPMVSCMGR_STATUS_VGIDSSIMULATOR_DESTROYING = 6
    TPMVSCMGR_STATUS_VREADER_INITIALIZING = 7
    TPMVSCMGR_STATUS_VREADER_CREATING = 8
    TPMVSCMGR_STATUS_VREADER_DESTROYING = 9
    TPMVSCMGR_STATUS_GENERATE_WAITING = 10
    TPMVSCMGR_STATUS_GENERATE_AUTHENTICATING = 11
    TPMVSCMGR_STATUS_GENERATE_RUNNING = 12
    TPMVSCMGR_STATUS_CARD_CREATED = 13
    TPMVSCMGR_STATUS_CARD_DESTROYED = 14


class ReportProgress_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("Status", 0, TPMVSCMGR_STATUS)]


class ReportProgress_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class TPMVSCMGR_ERROR(IntEnum):
    TPMVSCMGR_ERROR_IMPERSONATION = 1
    TPMVSCMGR_ERROR_PIN_COMPLEXITY = 2
    TPMVSCMGR_ERROR_READER_COUNT_LIMIT = 3
    TPMVSCMGR_ERROR_TERMINAL_SERVICES_SESSION = 4
    TPMVSCMGR_ERROR_VTPMSMARTCARD_INITIALIZE = 5
    TPMVSCMGR_ERROR_VTPMSMARTCARD_CREATE = 6
    TPMVSCMGR_ERROR_VTPMSMARTCARD_DESTROY = 7
    TPMVSCMGR_ERROR_VGIDSSIMULATOR_INITIALIZE = 8
    TPMVSCMGR_ERROR_VGIDSSIMULATOR_CREATE = 9
    TPMVSCMGR_ERROR_VGIDSSIMULATOR_DESTROY = 10
    TPMVSCMGR_ERROR_VGIDSSIMULATOR_WRITE_PROPERTY = 11
    TPMVSCMGR_ERROR_VGIDSSIMULATOR_READ_PROPERTY = 12
    TPMVSCMGR_ERROR_VREADER_INITIALIZE = 13
    TPMVSCMGR_ERROR_VREADER_CREATE = 14
    TPMVSCMGR_ERROR_VREADER_DESTROY = 15
    TPMVSCMGR_ERROR_GENERATE_LOCATE_READER = 16
    TPMVSCMGR_ERROR_GENERATE_FILESYSTEM = 17
    TPMVSCMGR_ERROR_CARD_CREATE = 18
    TPMVSCMGR_ERROR_CARD_DESTROY = 19


class ReportError_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("Error", 0, TPMVSCMGR_ERROR)]


class ReportError_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


ITPMVIRTUALSMARTCARDMANAGERSTATUSCALLBACK_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(ReportProgress_Request, ReportProgress_Response),
    4: DceRpcOp(ReportError_Request, ReportError_Response),
}
register_com_interface(
    name="ITpmVirtualSmartCardManagerStatusCallback",
    uuid=uuid.UUID("1A1BB35F-ABB8-451C-A1AE-33D98F1BEF4A"),
    opnums=ITPMVIRTUALSMARTCARDMANAGERSTATUSCALLBACK_OPNUMS,
)


class MInterfacePointer(NDRPacket):
    ALIGNMENT = (4, 4)
    DEPORTED_CONFORMANTS = ["abData"]
    fields_desc = [
        NDRIntField("ulCntData", None, size_of="abData"),
        NDRConfStrLenField(
            "abData", "", size_is=lambda pkt: pkt.ulCntData, conformant_in_struct=True
        ),
    ]


class CreateVirtualSmartCard_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszFriendlyName", ""),
        NDRByteField("bAdminAlgId", 0),
        NDRConfStrLenField("pbAdminKey", "", size_is=lambda pkt: pkt.cbAdminKey),
        NDRIntField("cbAdminKey", None, size_of="pbAdminKey"),
        NDRFullPointerField(
            NDRConfStrLenField("pbAdminKcv", "", size_is=lambda pkt: pkt.cbAdminKcv)
        ),
        NDRIntField("cbAdminKcv", None, size_of="pbAdminKcv"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPuk", "", size_is=lambda pkt: pkt.cbPuk)
        ),
        NDRIntField("cbPuk", None, size_of="pbPuk"),
        NDRConfStrLenField("pbPin", "", size_is=lambda pkt: pkt.cbPin),
        NDRIntField("cbPin", None, size_of="pbPin"),
        NDRSignedIntField("fGenerate", 0),
        NDRFullPointerField(
            NDRPacketField("pStatusCallback", MInterfacePointer(), MInterfacePointer)
        ),
    ]


class CreateVirtualSmartCard_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppszInstanceId", "")),
        NDRSignedIntField("pfNeedReboot", 0),
        NDRIntField("status", 0),
    ]


class DestroyVirtualSmartCard_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszInstanceId", ""),
        NDRFullPointerField(
            NDRPacketField("pStatusCallback", MInterfacePointer(), MInterfacePointer)
        ),
    ]


class DestroyVirtualSmartCard_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pfNeedReboot", 0), NDRIntField("status", 0)]


ITPMVIRTUALSMARTCARDMANAGER_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateVirtualSmartCard_Request, CreateVirtualSmartCard_Response),
    4: DceRpcOp(DestroyVirtualSmartCard_Request, DestroyVirtualSmartCard_Response),
}
register_com_interface(
    name="ITpmVirtualSmartCardManager",
    uuid=uuid.UUID("112B1DFF-D9DC-41F7-869F-D67FEE7CB591"),
    opnums=ITPMVIRTUALSMARTCARDMANAGER_OPNUMS,
)


class CreateVirtualSmartCardWithPinPolicy_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszFriendlyName", ""),
        NDRByteField("bAdminAlgId", 0),
        NDRConfStrLenField("pbAdminKey", "", size_is=lambda pkt: pkt.cbAdminKey),
        NDRIntField("cbAdminKey", None, size_of="pbAdminKey"),
        NDRFullPointerField(
            NDRConfStrLenField("pbAdminKcv", "", size_is=lambda pkt: pkt.cbAdminKcv)
        ),
        NDRIntField("cbAdminKcv", None, size_of="pbAdminKcv"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPuk", "", size_is=lambda pkt: pkt.cbPuk)
        ),
        NDRIntField("cbPuk", None, size_of="pbPuk"),
        NDRConfStrLenField("pbPin", "", size_is=lambda pkt: pkt.cbPin),
        NDRIntField("cbPin", None, size_of="pbPin"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPinPolicy", "", size_is=lambda pkt: pkt.cbPinPolicy)
        ),
        NDRIntField("cbPinPolicy", None, size_of="pbPinPolicy"),
        NDRSignedIntField("fGenerate", 0),
        NDRFullPointerField(
            NDRPacketField("pStatusCallback", MInterfacePointer(), MInterfacePointer)
        ),
    ]


class CreateVirtualSmartCardWithPinPolicy_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppszInstanceId", "")),
        NDRSignedIntField("pfNeedReboot", 0),
        NDRIntField("status", 0),
    ]


ITPMVIRTUALSMARTCARDMANAGER2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateVirtualSmartCard_Request, CreateVirtualSmartCard_Response),
    4: DceRpcOp(DestroyVirtualSmartCard_Request, DestroyVirtualSmartCard_Response),
    5: DceRpcOp(
        CreateVirtualSmartCardWithPinPolicy_Request,
        CreateVirtualSmartCardWithPinPolicy_Response,
    ),
}
register_com_interface(
    name="ITpmVirtualSmartCardManager2",
    uuid=uuid.UUID("FDF8A2B9-02DE-47F4-BC26-AA85AB5E5267"),
    opnums=ITPMVIRTUALSMARTCARDMANAGER2_OPNUMS,
)


class TPMVSC_ATTESTATION_TYPE(IntEnum):
    TPMVSC_ATTESTATION_NONE = 0
    TPMVSC_ATTESTATION_AIK_ONLY = 1
    TPMVSC_ATTESTATION_AIK_AND_CERTIFICATE = 2


class CreateVirtualSmartCardWithAttestation_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszFriendlyName", ""),
        NDRByteField("bAdminAlgId", 0),
        NDRConfStrLenField("pbAdminKey", "", size_is=lambda pkt: pkt.cbAdminKey),
        NDRIntField("cbAdminKey", None, size_of="pbAdminKey"),
        NDRFullPointerField(
            NDRConfStrLenField("pbAdminKcv", "", size_is=lambda pkt: pkt.cbAdminKcv)
        ),
        NDRIntField("cbAdminKcv", None, size_of="pbAdminKcv"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPuk", "", size_is=lambda pkt: pkt.cbPuk)
        ),
        NDRIntField("cbPuk", None, size_of="pbPuk"),
        NDRConfStrLenField("pbPin", "", size_is=lambda pkt: pkt.cbPin),
        NDRIntField("cbPin", None, size_of="pbPin"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPinPolicy", "", size_is=lambda pkt: pkt.cbPinPolicy)
        ),
        NDRIntField("cbPinPolicy", None, size_of="pbPinPolicy"),
        NDRIntEnumField("attestationType", 0, TPMVSC_ATTESTATION_TYPE),
        NDRSignedIntField("fGenerate", 0),
        NDRFullPointerField(
            NDRPacketField("pStatusCallback", MInterfacePointer(), MInterfacePointer)
        ),
    ]


class CreateVirtualSmartCardWithAttestation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ppszInstanceId", "")),
        NDRIntField("status", 0),
    ]


ITPMVIRTUALSMARTCARDMANAGER3_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateVirtualSmartCard_Request, CreateVirtualSmartCard_Response),
    4: DceRpcOp(DestroyVirtualSmartCard_Request, DestroyVirtualSmartCard_Response),
    5: DceRpcOp(
        CreateVirtualSmartCardWithPinPolicy_Request,
        CreateVirtualSmartCardWithPinPolicy_Response,
    ),
    6: DceRpcOp(
        CreateVirtualSmartCardWithAttestation_Request,
        CreateVirtualSmartCardWithAttestation_Response,
    ),
}
register_com_interface(
    name="ITpmVirtualSmartCardManager3",
    uuid=uuid.UUID("3C745A97-F375-4150-BE17-5950F694C699"),
    opnums=ITPMVIRTUALSMARTCARDMANAGER3_OPNUMS,
)
