// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/QMIThread.c
// Function: requestSetEthMode
static int requestSetEthMode(PROFILE_T *profile) {
    PQCQMIMSG pRequest;
    PQCQMIMSG pResponse = NULL;
    PQMUX_MSG pMUXMsg;
    int err;
    PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV linkProto;
    UCHAR IpPreference;
    UCHAR autoconnect_setting = 0;
    QMAP_SETTING qmap_settings = {0};

    qmap_settings.size = sizeof(qmap_settings);
    
    if (profile->qmap_mode) {
        profile->rawIP = 1;
        s_9x07 = profile->rawIP;
        
        qmap_settings.MuxId = profile->muxid;

        if (profile->hardware_interface == HARDWARE_PCIE) { //SDX20_PCIE
            qmap_settings.rx_urb_size = profile->qmap_size; //SDX24&SDX55 support 32KB 
            qmap_settings.ep_type = DATA_EP_TYPE_PCIE;
            qmap_settings.iface_id = 0x04;
        }
        else { // for MDM9x07&MDM9x40&SDX20 USB
            qmap_settings.rx_urb_size = profile->qmap_size; //SDX24&SDX55 support 32KB
            qmap_settings.ep_type = DATA_EP_TYPE_HSUSB;
            qmap_settings.iface_id = 0x04;
        }

        qmap_settings.ul_data_aggregation_max_datagrams = 11; //by test result, 11 can get best TPUT
        qmap_settings.ul_data_aggregation_max_size = 8*1024;
        qmap_settings.dl_minimum_padding = 0; //no effect when register to real netowrk
        if(profile->qmap_version != 0x09)
            profile->qmap_version = 0x05;

        qmap_version = profile->qmap_version;
        if (profile->rmnet_info.size) {
            qmap_settings.rx_urb_size = profile->rmnet_info.rx_urb_size;
            qmap_settings.ep_type = profile->rmnet_info.ep_type;
            qmap_settings.iface_id = profile->rmnet_info.iface_id;
            qmap_settings.dl_minimum_padding = profile->rmnet_info.dl_minimum_padding;
            qmap_version = profile->rmnet_info.qmap_version;
        }

        if (!profile->wda_client) {
            if (qmidev_is_gobinet(profile->qmichannel)) {
                //when QMAP enabled, set data format in GobiNet driver
            }
            else if (profile->proxy[0]) {
                /* the first running 'quectel-cm' had alloc wda client and set data format,
                   so we can ingore to set data format here. */
            }
            goto skip_WdaSetDataFormat;
        }
    }

    pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_ADMIN, QMIWDS_ADMIN_SET_DATA_FORMAT_REQ, WdaSetDataFormat, (void *)&qmap_settings);
    err = QmiThreadSendQMI(pRequest, &pResponse);
    qmi_rsp_check_and_return();

    linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x11);
    if (linkProto != NULL) {
        profile->rawIP = (le32_to_cpu(linkProto->Value) == 2);
        s_9x07 = profile->rawIP; //MDM90x7 only support RAW IP, do not support Eth
    }

    linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x16);
    if (linkProto != NULL && profile->qmap_mode) {
        qmap_settings.rx_urb_size = le32_to_cpu(linkProto->Value);
        dbg_time("qmap_settings.rx_urb_size = %u", qmap_settings.rx_urb_size); //must same as rx_urb_size defined in GobiNet&qmi_wwan driver
    }

#ifdef QUECTEL_UL_DATA_AGG
    if (qmap_settings.ul_data_aggregation_max_datagrams)
    {
        linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x17);
        if (linkProto != NULL) {
            qmap_settings.ul_data_aggregation_max_datagrams = MIN(qmap_settings.ul_data_aggregation_max_datagrams, le32_to_cpu(linkProto->Value));
            dbg_time("qmap_settings.ul_data_aggregation_max_datagrams  = %u", qmap_settings.ul_data_aggregation_max_datagrams);
        }

        linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x18);
        if (linkProto != NULL) {
            qmap_settings.ul_data_aggregation_max_size = MIN(qmap_settings.ul_data_aggregation_max_size, le32_to_cpu(linkProto->Value));
            dbg_time("qmap_settings.ul_data_aggregation_max_size       = %u", qmap_settings.ul_data_aggregation_max_size);
        }

        linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x1A);
        if (linkProto != NULL) {
            qmap_settings.dl_minimum_padding = le32_to_cpu(linkProto->Value);
            dbg_time("qmap_settings.dl_minimum_padding                 = %u", qmap_settings.dl_minimum_padding);
        }

	if (qmap_settings.ul_data_aggregation_max_datagrams > 1) {
		ql_set_driver_qmap_setting(profile, &qmap_settings);
	}
    }
#endif

    free(pResponse);

skip_WdaSetDataFormat:
    if (profile->enable_ipv4) {
    	if (profile->qmapnet_adapter[0]) {
            // bind wds mux data port
        	pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_BIND_MUX_DATA_PORT_REQ , WdsSetQMUXBindMuxDataPort, (void *)&qmap_settings);
        	err = QmiThreadSendQMI(pRequest, &pResponse);
        	qmi_rsp_check_and_return();
        	if (pResponse) free(pResponse);
        }

        // set ipv4
    	IpPreference = IpFamilyV4;
    	pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ, WdsSetClientIPFamilyPref, (void *)&IpPreference);
    	err = QmiThreadSendQMI(pRequest, &pResponse);
    	if (pResponse) free(pResponse);
    }

    if (profile->enable_ipv6) {
        if (profile->qmapnet_adapter[0]) {
            // bind wds ipv6 mux data port
            pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_IPV6, QMIWDS_BIND_MUX_DATA_PORT_REQ , WdsSetQMUXBindMuxDataPort, (void *)&qmap_settings);
            err = QmiThreadSendQMI(pRequest, &pResponse);
            qmi_rsp_check_and_return();
            if (pResponse) free(pResponse);
        }

        // set ipv6
        IpPreference = IpFamilyV6;
        pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_IPV6, QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ, WdsSetClientIPFamilyPref, (void *)&IpPreference);
        err = QmiThreadSendQMI(pRequest, &pResponse);
        qmi_rsp_check_and_return();
        if (pResponse) free(pResponse);
    }

    pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_SET_AUTO_CONNECT_REQ , WdsSetAutoConnect, (void *)&autoconnect_setting);
    QmiThreadSendQMI(pRequest, &pResponse);
    if (pResponse) free(pResponse);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
andq $0x0, (%rsp)
movq %rdi, %rbx
movb $0x0, 0xe(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movups %xmm0, 0x14(%rsp)
movl $0x20, 0x10(%rsp)
cmpl $0x0, 0x10a(%rdi)
je 0xa525
pushq $0x1
popq %rax
movl %eax, 0x11a(%rbx)
movl %eax, 0x1ee73(%rip)     # 0x292f8
movl 0x11e(%rbx), %eax
movl %eax, 0x20(%rsp)
movl 0x10e(%rbx), %eax
xorl %ecx, %ecx
cmpl $0x5, 0x1bd(%rbx)
sete %cl
orl $0x2, %ecx
movl %eax, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
movl $0x4, 0x1c(%rsp)
movabsq $0x20000000000b, %rax   # imm = 0x20000000000B
movq %rax, 0x24(%rsp)
cmpl $0x9, 0x112(%rbx)
jne 0xa4d0
pushq $0x9
jmp 0xa4dc
movl $0x5, 0x112(%rbx)
pushq $0x5
popq %rax
movl %eax, 0x1ee19(%rip)     # 0x292fc
cmpl $0x0, 0x32e(%rbx)
je 0xa518
movq 0x332(%rbx), %rax
movq %rax, 0x14(%rsp)
movl 0x33a(%rbx), %eax
movl %eax, 0x1c(%rsp)
movl 0x346(%rbx), %eax
movl %eax, 0x2c(%rsp)
movl 0x342(%rbx), %eax
movl %eax, 0x1ede4(%rip)     # 0x292fc
cmpl $0x0, 0x122(%rbx)
je 0xa863
leaq 0x314e(%rip), %rdx      # 0xd67a
pushq $0x1a
popq %rdi
pushq $0x20
popq %rsi
leaq 0x10(%rsp), %rcx
callq 0xd53c
leaq 0x14298(%rip), %rcx     # 0x1e7db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xa5d5
movq 0x1ea44(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x141fe(%rip), %rsi     # 0x1e781
leaq 0x14251(%rip), %rcx     # 0x1e7db
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x1f707(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xaace
callq 0xe343
leaq 0x141c8(%rip), %rsi     # 0x1e781
leaq 0x1421b(%rip), %rcx     # 0x1e7db
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xaace
movzwl 0x10(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movzwl 0x12(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movq (%rsp), %rdi
addq $0x9, %rdi
pushq $0x11
popq %rsi
callq 0x9e14
testq %rax, %rax
je 0xa62e
movl 0x3(%rax), %edi
callq 0xe741
xorl %ecx, %ecx
cmpl $0x2, %eax
sete %cl
movl %ecx, 0x11a(%rbx)
movl %ecx, 0x1ecca(%rip)     # 0x292f8
movq (%rsp), %rdi
addq $0x9, %rdi
pushq $0x16
popq %rsi
callq 0x9e14
testq %rax, %rax
je 0xa6ab
cmpl $0x0, 0x10a(%rbx)
je 0xa6ab
movl 0x3(%rax), %edi
callq 0xe741
movl %eax, 0x14(%rsp)
movq 0x1e959(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movl 0x14(%rsp), %ecx
leaq 0x1417b(%rip), %rsi     # 0x1e7ed
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1f622(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0xa6ab
callq 0xe343
movl 0x14(%rsp), %ecx
leaq 0x1414f(%rip), %rsi     # 0x1e7ed
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x0, 0x24(%rsp)
je 0xa85a
movq (%rsp), %rdi
addq $0x9, %rdi
pushq $0x17
popq %rsi
callq 0x9e14
testq %rax, %rax
je 0xa744
movq %rax, %r14
movl 0x24(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xe741
cmpl %eax, %ebp
jae 0xa6e4
movl 0x24(%rsp), %eax
jmp 0xa6ed
movl 0x3(%r14), %edi
callq 0xe741
movl %eax, 0x24(%rsp)
movq 0x1e8c0(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movl 0x24(%rsp), %ecx
leaq 0x14107(%rip), %rsi     # 0x1e812
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1f589(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0xa744
callq 0xe343
movl 0x24(%rsp), %ecx
leaq 0x140db(%rip), %rsi     # 0x1e812
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
pushq $0x18
popq %rsi
callq 0x9e14
testq %rax, %rax
je 0xa7d2
movq %rax, %r14
movl 0x28(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xe741
cmpl %eax, %ebp
jae 0xa772
movl 0x28(%rsp), %eax
jmp 0xa77b
movl 0x3(%r14), %edi
callq 0xe741
movl %eax, 0x28(%rsp)
movq 0x1e832(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movl 0x28(%rsp), %ecx
leaq 0x140b5(%rip), %rsi     # 0x1e84e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1f4fb(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0xa7d2
callq 0xe343
movl 0x28(%rsp), %ecx
leaq 0x14089(%rip), %rsi     # 0x1e84e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
pushq $0x1a
popq %rsi
callq 0x9e14
testq %rax, %rax
je 0xa846
movl 0x3(%rax), %edi
callq 0xe741
movl %eax, 0x2c(%rsp)
movq 0x1e7be(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movl 0x2c(%rsp), %ecx
leaq 0x1407d(%rip), %rsi     # 0x1e88a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1f487(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0xa846
callq 0xe343
movl 0x2c(%rsp), %ecx
leaq 0x14051(%rip), %rsi     # 0x1e88a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x2, 0x24(%rsp)
jb 0xa85a
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xef07
movq (%rsp), %rdi
callq 0x5040
cmpb $0x0, 0x50(%rbx)
je 0xa931
cmpb $0x0, 0xca(%rbx)
je 0xa8f5
leaq 0x2f79(%rip), %rdx      # 0xd7f6
pushq $0x1
popq %rdi
leaq 0x10(%rsp), %rcx
movl $0xa2, %esi
callq 0xd53c
leaq 0x13f45(%rip), %rcx     # 0x1e7db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa56d
movzwl 0x10(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movzwl 0x12(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movq (%rsp), %rdi
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x4, (%rcx)
leaq 0x2f60(%rip), %rdx      # 0xd864
pushq $0x1
popq %rdi
pushq $0x4d
popq %rsi
callq 0xd53c
leaq 0x13ec5(%rip), %rcx     # 0x1e7db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movq (%r14), %rdi
callq 0x5040
cmpb $0x0, 0x51(%rbx)
je 0xaae6
cmpb $0x0, 0xca(%rbx)
je 0xa9bf
leaq 0x2eab(%rip), %rdx      # 0xd7f6
pushq $0x11
popq %rdi
leaq 0x10(%rsp), %rcx
movl $0xa2, %esi
callq 0xd53c
leaq 0x13e77(%rip), %rcx     # 0x1e7db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa56d
movzwl 0x10(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movzwl 0x12(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movq (%rsp), %rdi
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x6, (%rcx)
leaq 0x2e96(%rip), %rdx      # 0xd864
pushq $0x11
popq %rdi
pushq $0x4d
popq %rsi
callq 0xd53c
leaq 0x13dfb(%rip), %rcx     # 0x1e7db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa56d
movzwl 0x10(%r12), %edi
callq 0xe73e
testw %ax, %ax
jne 0xaa32
movzwl 0x12(%r12), %edi
callq 0xe73e
testw %ax, %ax
je 0xaadd
movzwl 0x12(%r12), %edi
callq 0xe73e
movl %eax, %ebx
movq 0x1e572(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movq %rax, %r15
movzwl 0x10(%r12), %edi
callq 0xe73e
movzwl %ax, %r8d
movzwl %bx, %ebp
leaq 0x13d29(%rip), %rsi     # 0x1e793
leaq 0x13d6a(%rip), %rcx     # 0x1e7db
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x1f220(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xaac5
callq 0xe343
movq %rax, %r14
movzwl 0x10(%r12), %edi
callq 0xe73e
movzwl %ax, %r8d
leaq 0x13ce5(%rip), %rsi     # 0x1e793
leaq 0x13d26(%rip), %rcx     # 0x1e7db
movq %rbx, %rdi
movq %r14, %rdx
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
callq 0x5040
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdi
callq 0x5040
leaq 0x2da4(%rip), %rdx      # 0xd891
pushq $0x1
popq %rdi
pushq $0x51
popq %rsi
leaq 0xe(%rsp), %rcx
callq 0xd53c
leaq 0x13cd7(%rip), %rcx     # 0x1e7db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
movq (%rbx), %rdi
callq 0x5040
xorl %ebp, %ebp
jmp 0xaace