// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %rbx
movq $0x0, (%rsp)
movb $0x0, 0xe(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movups %xmm0, 0x14(%rsp)
movl $0x20, 0x10(%rsp)
cmpl $0x0, 0x10a(%rdi)
je 0xa92d
movl $0x1, %eax
movl %eax, 0x11a(%rbx)
movl %eax, 0x1fa6e(%rip)     # 0x2a2f8
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)
movl $0x9, %eax
cmpl $0x9, 0x112(%rbx)
je 0xa8e5
movl $0x5, 0x112(%rbx)
movl $0x5, %eax
movl %eax, 0x1fa11(%rip)     # 0x2a2fc
cmpl $0x0, 0x32e(%rbx)
je 0xa920
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, 0x1f9dc(%rip)     # 0x2a2fc
cmpl $0x0, 0x122(%rbx)
je 0xac79
leaq 0x31ae(%rip), %rdx      # 0xdae2
leaq 0x10(%rsp), %rcx
movl $0x1a, %edi
movl $0x20, %esi
callq 0xd9a2
leaq 0x15e8c(%rip), %rcx     # 0x207db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xa9e1
movq 0x1f640(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x15df2(%rip), %rsi     # 0x20781
leaq 0x15e45(%rip), %rcx     # 0x207db
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x202fb(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xaf0b
callq 0xea3b
leaq 0x15dbc(%rip), %rsi     # 0x20781
leaq 0x15e0f(%rip), %rcx     # 0x207db
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xaf0b
movzwl 0x10(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movzwl 0x12(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x11, %esi
callq 0xa1f8
testq %rax, %rax
je 0xaa3c
movl 0x3(%rax), %edi
callq 0xee76
xorl %ecx, %ecx
cmpl $0x2, %eax
sete %cl
movl %ecx, 0x11a(%rbx)
movl %ecx, 0x1f8bc(%rip)     # 0x2a2f8
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x16, %esi
callq 0xa1f8
testq %rax, %rax
je 0xaabb
cmpl $0x0, 0x10a(%rbx)
je 0xaabb
movl 0x3(%rax), %edi
callq 0xee76
movl %eax, 0x14(%rsp)
movq 0x1f551(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movl 0x14(%rsp), %ecx
leaq 0x15d6b(%rip), %rsi     # 0x207ed
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x20212(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xaabb
callq 0xea3b
movl 0x14(%rsp), %ecx
leaq 0x15d3f(%rip), %rsi     # 0x207ed
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x0, 0x24(%rsp)
je 0xac70
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x17, %esi
callq 0xa1f8
testq %rax, %rax
je 0xab56
movq %rax, %r14
movl 0x24(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xee76
cmpl %eax, %ebp
jae 0xaaf6
movl 0x24(%rsp), %eax
jmp 0xaaff
movl 0x3(%r14), %edi
callq 0xee76
movl %eax, 0x24(%rsp)
movq 0x1f4b6(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movl 0x24(%rsp), %ecx
leaq 0x15cf5(%rip), %rsi     # 0x20812
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x20177(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xab56
callq 0xea3b
movl 0x24(%rsp), %ecx
leaq 0x15cc9(%rip), %rsi     # 0x20812
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x18, %esi
callq 0xa1f8
testq %rax, %rax
je 0xabe6
movq %rax, %r14
movl 0x28(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xee76
cmpl %eax, %ebp
jae 0xab86
movl 0x28(%rsp), %eax
jmp 0xab8f
movl 0x3(%r14), %edi
callq 0xee76
movl %eax, 0x28(%rsp)
movq 0x1f426(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movl 0x28(%rsp), %ecx
leaq 0x15ca1(%rip), %rsi     # 0x2084e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x200e7(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xabe6
callq 0xea3b
movl 0x28(%rsp), %ecx
leaq 0x15c75(%rip), %rsi     # 0x2084e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x1a, %esi
callq 0xa1f8
testq %rax, %rax
je 0xac5c
movl 0x3(%rax), %edi
callq 0xee76
movl %eax, 0x2c(%rsp)
movq 0x1f3b0(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movl 0x2c(%rsp), %ecx
leaq 0x15c67(%rip), %rsi     # 0x2088a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x20071(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xac5c
callq 0xea3b
movl 0x2c(%rsp), %ecx
leaq 0x15c3b(%rip), %rsi     # 0x2088a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x2, 0x24(%rsp)
jb 0xac70
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xf672
movq (%rsp), %rdi
callq 0x5040
cmpb $0x0, 0x50(%rbx)
je 0xad5b
cmpb $0x0, 0xca(%rbx)
je 0xad16
leaq 0x2fe6(%rip), %rdx      # 0xdc7d
leaq 0x10(%rsp), %rcx
movl $0x1, %edi
movl $0xa2, %esi
callq 0xd9a2
leaq 0x15b29(%rip), %rcx     # 0x207db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa979
movzwl 0x10(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movzwl 0x12(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xad16
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x4, (%rcx)
leaq 0x2fd0(%rip), %rdx      # 0xdcf5
movl $0x1, %edi
movl $0x4d, %esi
callq 0xd9a2
leaq 0x15aa0(%rip), %rcx     # 0x207db
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movq (%r14), %rdi
testq %rdi, %rdi
je 0xad5b
callq 0x5040
cmpb $0x0, 0x51(%rbx)
je 0xaf28
cmpb $0x0, 0xca(%rbx)
je 0xadf8
leaq 0x2f04(%rip), %rdx      # 0xdc7d
leaq 0x10(%rsp), %rcx
movl $0x11, %edi
movl $0xa2, %esi
callq 0xd9a2
leaq 0x15a47(%rip), %rcx     # 0x207db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa979
movzwl 0x10(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movzwl 0x12(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xadf8
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x6, (%rcx)
leaq 0x2eee(%rip), %rdx      # 0xdcf5
movl $0x11, %edi
movl $0x4d, %esi
callq 0xd9a2
leaq 0x159be(%rip), %rcx     # 0x207db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xa979
movzwl 0x10(%r12), %edi
callq 0xee73
testw %ax, %ax
jne 0xae6f
movzwl 0x12(%r12), %edi
callq 0xee73
testw %ax, %ax
je 0xaf1a
movzwl 0x12(%r12), %edi
callq 0xee73
movl %eax, %ebx
movq 0x1f13d(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movq %rax, %r15
movzwl 0x10(%r12), %edi
callq 0xee73
movzwl %ax, %r8d
movzwl %bx, %ebp
leaq 0x158ec(%rip), %rsi     # 0x20793
leaq 0x1592d(%rip), %rcx     # 0x207db
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x1fde3(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xaf02
callq 0xea3b
movq %rax, %r14
movzwl 0x10(%r12), %edi
callq 0xee73
movzwl %ax, %r8d
leaq 0x158a8(%rip), %rsi     # 0x20793
leaq 0x158e9(%rip), %rcx     # 0x207db
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
testq %rdi, %rdi
je 0xaf28
callq 0x5040
leaq 0x2df5(%rip), %rdx      # 0xdd24
leaq 0xe(%rsp), %rcx
movl $0x1, %edi
movl $0x51, %esi
callq 0xd9a2
leaq 0x15891(%rip), %rcx     # 0x207db
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
movq (%rbx), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
jne 0xaf06
jmp 0xaf0b