// File: /workspace/github_c_makefile_star2_O2/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
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl 0x4(%rsi), %ebp
movb $0x10, 0x7(%rdi)
pushq $0x1
popq %rdi
callq 0xe749
movw %ax, 0x8(%rbx)
movw $0x1100, 0xa(%rbx)      # imm = 0x1100
pushq $0x4
popq %rdi
callq 0xe749
movw %ax, 0xc(%rbx)
testl %ebp, %ebp
je 0xd7bb
pushq $0x2
popq %rdi
callq 0xe74c
movl %eax, 0xe(%rbx)
movb $0x12, 0x12(%rbx)
pushq $0x4
popq %rbp
movl %ebp, %edi
callq 0xe749
movw %ax, 0x13(%rbx)
movl 0x1bc28(%rip), %edi     # 0x292fc
callq 0xe74c
movl %eax, 0x15(%rbx)
movb $0x13, 0x19(%rbx)
movl %ebp, %edi
callq 0xe749
movw %ax, 0x1a(%rbx)
movl 0x1bc0b(%rip), %edi     # 0x292fc
callq 0xe74c
movl %eax, 0x1c(%rbx)
movb $0x15, 0x20(%rbx)
movl %ebp, %edi
callq 0xe749
movw %ax, 0x21(%rbx)
movl 0x4(%r14), %edi
shrl $0x9, %edi
callq 0xe74c
movl %eax, 0x23(%rbx)
movb $0x16, 0x27(%rbx)
movl %ebp, %edi
callq 0xe749
movw %ax, 0x28(%rbx)
movl 0x4(%r14), %edi
callq 0xe74c
movl %eax, 0x2a(%rbx)
movb $0x17, 0x2e(%rbx)
pushq $0x8
popq %rdi
callq 0xe749
movw %ax, 0x2f(%rbx)
movl 0x8(%r14), %edi
callq 0xe74c
movl %eax, 0x31(%rbx)
movl 0xc(%r14), %edi
callq 0xe74c
movl %eax, 0x35(%rbx)
cmpl $0x0, 0x14(%r14)
je 0xd7eb
movb $0x19, 0x39(%rbx)
pushq $0x4
popq %rbp
movl %ebp, %edi
callq 0xe749
movw %ax, 0x3a(%rbx)
movl 0x1c(%r14), %edi
callq 0xe74c
movl %eax, 0x3c(%rbx)
movb $0x1b, 0x40(%rbx)
movl %ebp, %edi
callq 0xe749
movw %ax, 0x41(%rbx)
movl 0x14(%r14), %edi
callq 0xe74c
movl %eax, 0x43(%rbx)
movb $0x1c, 0x47(%rbx)
movl %ebp, %edi
callq 0xe749
movw %ax, 0x48(%rbx)
movl 0x18(%r14), %edi
movw $0x4b, %bp
pushq $0x4a
popq %r14
jmp 0xd7e0
pushq $0x1
popq %rdi
callq 0xe74c
movl %eax, 0xe(%rbx)
movb $0x13, 0x12(%rbx)
pushq $0x4
popq %rdi
callq 0xe749
movw %ax, 0x13(%rbx)
movw $0x16, %bp
pushq $0x15
popq %r14
xorl %edi, %edi
callq 0xe74c
movl %eax, (%rbx,%r14)
jmp 0xd7ef
movw $0x36, %bp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq