// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/QMIThread.c
// Function: WdaSetDataFormat
static USHORT WdaSetDataFormat(PQMUX_MSG pMUXMsg, void *arg) {
    QMAP_SETTING *qmap_settings = (QMAP_SETTING *)arg;

    if (qmap_settings->rx_urb_size == 0) {
        PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV_QOS pWdsAdminQosTlv;
        PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV linkProto;
        PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV dlTlp;

        pWdsAdminQosTlv = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV_QOS)(&pMUXMsg->QMUXMsgHdr + 1);
        pWdsAdminQosTlv->TLVType = 0x10;
        pWdsAdminQosTlv->TLVLength = cpu_to_le16(0x0001);
        pWdsAdminQosTlv->QOSSetting = 0; /* no-QOS header */

        linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)(pWdsAdminQosTlv + 1);
        linkProto->TLVType = 0x11;
        linkProto->TLVLength = cpu_to_le16(4);
        linkProto->Value = cpu_to_le32(0x01);     /* Set Ethernet  mode */

        dlTlp = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)(linkProto + 1);;
        dlTlp->TLVType = 0x13;
        dlTlp->TLVLength = cpu_to_le16(4);
        dlTlp->Value = cpu_to_le32(0x00);

        if (sizeof(*linkProto) != 7 )
            dbg_time("%s sizeof(*linkProto) = %zu, is not 7!", __func__, sizeof(*linkProto) );

        return sizeof(QCQMUX_MSG_HDR) + sizeof(*pWdsAdminQosTlv) + sizeof(*linkProto) + sizeof(*dlTlp);
    } 
    else {
    //Indicates whether the Quality of Service(QOS) data format is used by the client.
        pMUXMsg->SetDataFormatReq.QosDataFormatTlv.TLVType = 0x10;
        pMUXMsg->SetDataFormatReq.QosDataFormatTlv.TLVLength = cpu_to_le16(0x0001);
        pMUXMsg->SetDataFormatReq.QosDataFormatTlv.QOSSetting = 0; /* no-QOS header */
		
    //Underlying Link Layer Protocol
        pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.TLVType = 0x11; 
        pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.Value = cpu_to_le32(0x02);     /* Set IP  mode */

    //Uplink (UL) data aggregation protocol to be used for uplink data transfer.
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.TLVType = 0x12; 
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.Value = cpu_to_le32(qmap_version); //UL QMAP is enabled
        
    //Downlink (DL) data aggregation protocol to be used for downlink data transfer
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.TLVType = 0x13; 
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.Value = cpu_to_le32(qmap_version); //DL QMAP is enabled
        
    //Maximum number of datagrams in a single aggregated packet on downlink
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.TLVType = 0x15; 
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.Value = cpu_to_le32(qmap_settings->rx_urb_size/512);
		
    //Maximum size in bytes of a single aggregated packet allowed on downlink
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.TLVType = 0x16; 
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.Value = cpu_to_le32(qmap_settings->rx_urb_size);

    //Peripheral End Point ID
        pMUXMsg->SetDataFormatReq.epTlv.TLVType = 0x17; 
        pMUXMsg->SetDataFormatReq.epTlv.TLVLength = cpu_to_le16(8);
        pMUXMsg->SetDataFormatReq.epTlv.ep_type = cpu_to_le32(qmap_settings->ep_type);
        pMUXMsg->SetDataFormatReq.epTlv.iface_id = cpu_to_le32(qmap_settings->iface_id); 

#ifdef QUECTEL_UL_DATA_AGG
        if (!qmap_settings->ul_data_aggregation_max_datagrams) {
            return ((size_t)&((QMIWDS_ADMIN_SET_DATA_FORMAT_REQ_MSG *)0)->DlMinimumPassingTlv);
        }
        
     //Maximum number of datagrams in a single aggregated packet on uplink
        pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.TLVType = 0x19; 
        pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.Value = cpu_to_le32(qmap_settings->dl_minimum_padding);
		
     //Maximum number of datagrams in a single aggregated packet on uplink
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.TLVType = 0x1B; 
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.Value = cpu_to_le32(qmap_settings->ul_data_aggregation_max_datagrams);
		
    //Maximum size in bytes of a single aggregated packet allowed on downlink
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.TLVType = 0x1C; 
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.TLVLength = cpu_to_le16(4);
        pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.Value = cpu_to_le32(qmap_settings->ul_data_aggregation_max_size);
#endif

        return sizeof(QMIWDS_ADMIN_SET_DATA_FORMAT_REQ_MSG);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x114f8
movq -0x10(%rbp), %rax
addq $0x3, %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb $0x10, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x3(%rax)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb $0x11, (%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x1(%rax)
movl $0x1, %edi
callq 0x14040
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x3(%rax)
movq -0x30(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x13, (%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x1(%rax)
xorl %edi, %edi
callq 0x14040
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x3(%rax)
movw $0x16, -0x2(%rbp)
jmp 0x11712
movq -0x10(%rbp), %rax
movb $0x10, 0x7(%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xa(%rax)
movq -0x10(%rbp), %rax
movb $0x11, 0xb(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0xc(%rax)
movl $0x2, %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xe(%rax)
movq -0x10(%rbp), %rax
movb $0x12, 0x12(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x13(%rax)
movl 0x25d94(%rip), %edi     # 0x37304
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x15(%rax)
movq -0x10(%rbp), %rax
movb $0x13, 0x19(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x1a(%rax)
movl 0x25d63(%rip), %edi     # 0x37304
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movb $0x15, 0x20(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x21(%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
shrl $0x9, %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x23(%rax)
movq -0x10(%rbp), %rax
movb $0x16, 0x27(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x28(%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2a(%rax)
movq -0x10(%rbp), %rax
movb $0x17, 0x2e(%rax)
movl $0x8, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2f(%rax)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x31(%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x35(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x11676
xorl %eax, %eax
addq $0x36, %rax
movw %ax, -0x2(%rbp)
jmp 0x11712
movq -0x10(%rbp), %rax
movb $0x19, 0x39(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x3a(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x10(%rbp), %rax
movb $0x1b, 0x40(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x41(%rax)
movq -0x20(%rbp), %rax
movl 0x14(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x43(%rax)
movq -0x10(%rbp), %rax
movb $0x1c, 0x47(%rax)
movl $0x4, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x48(%rax)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %edi
callq 0x14040
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4a(%rax)
movw $0x4b, -0x2(%rbp)
movw -0x2(%rbp), %ax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)