# 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-com] v12.0 (Tue, 23 Apr 2024)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- ITransactionStream (v0.0): 97199110-DB2E-11d1-A251-0000F805CA53
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid


from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfFieldListField,
    NDRConfStrLenField,
    NDRFullPointerField,
    NDRIntField,
    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 GetSeqAndTxViaExport_Request(NDRPacket):
    fields_desc = [
        NDRIntField("ulKnownSeq", 0),
        NDRIntField("ulcbWhereabouts", None, size_of="rgbWhereabouts"),
        NDRConfStrLenField(
            "rgbWhereabouts", "", size_is=lambda pkt: pkt.ulcbWhereabouts
        ),
    ]


class GetSeqAndTxViaExport_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pulCurrentSeq", 0),
        NDRIntField("pulcbExportCookie", None, size_of="prgbExportCookie"),
        NDRConfFieldListField(
            "prgbExportCookie",
            [],
            NDRFullPointerField(NDRByteField("", 0)),
            size_is=lambda pkt: pkt.pulcbExportCookie,
        ),
        NDRIntField("status", 0),
    ]


class GetSeqAndTxViaTransmitter_Request(NDRPacket):
    fields_desc = [NDRIntField("ulKnownSeq", 0)]


class GetSeqAndTxViaTransmitter_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pulCurrentSeq", 0),
        NDRIntField("pulcbTransmitterBuffer", None, size_of="prgbTransmitterBuffer"),
        NDRConfFieldListField(
            "prgbTransmitterBuffer",
            [],
            NDRFullPointerField(NDRByteField("", 0)),
            size_is=lambda pkt: pkt.pulcbTransmitterBuffer,
        ),
        NDRIntField("status", 0),
    ]


class GetTxViaExport_Request(NDRPacket):
    fields_desc = [
        NDRIntField("ulRequestSeq", 0),
        NDRIntField("ulcbWhereabouts", None, size_of="rgbWhereabouts"),
        NDRConfStrLenField(
            "rgbWhereabouts", "", size_is=lambda pkt: pkt.ulcbWhereabouts
        ),
    ]


class GetTxViaExport_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pulcbExportCookie", None, size_of="prgbExportCookie"),
        NDRConfFieldListField(
            "prgbExportCookie",
            [],
            NDRFullPointerField(NDRByteField("", 0)),
            size_is=lambda pkt: pkt.pulcbExportCookie,
        ),
        NDRIntField("status", 0),
    ]


class GetTxViaTransmitter_Request(NDRPacket):
    fields_desc = [NDRIntField("ulRequestSeq", 0)]


class GetTxViaTransmitter_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pulcbTransmitterBuffer", None, size_of="prgbTransmitterBuffer"),
        NDRConfFieldListField(
            "prgbTransmitterBuffer",
            [],
            NDRFullPointerField(NDRByteField("", 0)),
            size_is=lambda pkt: pkt.pulcbTransmitterBuffer,
        ),
        NDRIntField("status", 0),
    ]


ITRANSACTIONSTREAM_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetSeqAndTxViaExport_Request, GetSeqAndTxViaExport_Response),
    4: DceRpcOp(GetSeqAndTxViaTransmitter_Request, GetSeqAndTxViaTransmitter_Response),
    5: DceRpcOp(GetTxViaExport_Request, GetTxViaExport_Response),
    6: DceRpcOp(GetTxViaTransmitter_Request, GetTxViaTransmitter_Response),
}
register_com_interface(
    name="ITransactionStream",
    uuid=uuid.UUID("97199110-DB2E-11d1-A251-0000F805CA53"),
    opnums=ITRANSACTIONSTREAM_OPNUMS,
)
