// File: /workspace/github_c_makefile_star2_O1/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
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0x20, 0x10(%rsp)
cmpl $0x0, 0x10a(%rdi)
je 0xa9cf
movl $0x1, %eax
movl %eax, 0x11a(%rbx)
movl %eax, 0x1f9d8(%rip)     # 0x2a2f8
movl 0x11e(%rbx), %eax
movl %eax, 0x20(%rsp)
movl 0x10e(%rbx), %eax
xorl %ecx, %ecx
cmpl $0x5, 0x1bd(%rbx)
sete %cl
movl %eax, 0x14(%rsp)
orl $0x2, %ecx
movl %ecx, 0x18(%rsp)
movl $0x4, 0x1c(%rsp)
movabsq $0x20000000000b, %rax   # imm = 0x20000000000B
movq %rax, 0x24(%rsp)
movl $0x0, 0x2c(%rsp)
cmpl $0x9, 0x112(%rbx)
je 0xa979
movl $0x5, 0x112(%rbx)
movl 0x112(%rbx), %eax
movl %eax, 0x1f977(%rip)     # 0x2a2fc
cmpl $0x0, 0x32e(%rbx)
je 0xa9c2
movl 0x332(%rbx), %eax
movl %eax, 0x14(%rsp)
movl 0x336(%rbx), %eax
movl %eax, 0x18(%rsp)
movl 0x33a(%rbx), %eax
movl %eax, 0x1c(%rsp)
movl 0x346(%rbx), %eax
movl %eax, 0x2c(%rsp)
movl 0x342(%rbx), %eax
movl %eax, 0x1f93a(%rip)     # 0x2a2fc
cmpl $0x0, 0x122(%rbx)
je 0xad1b
leaq 0x3203(%rip), %rdx      # 0xdbd9
leaq 0x10(%rsp), %rcx
movl $0x1a, %edi
movl $0x20, %esi
callq 0xda86
leaq 0x15dee(%rip), %rcx     # 0x207df
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xaa83
movq 0x1f59e(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x15d54(%rip), %rsi     # 0x20785
leaq 0x15da7(%rip), %rcx     # 0x207df
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x20259(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xafad
callq 0xeb2f
leaq 0x15d1e(%rip), %rsi     # 0x20785
leaq 0x15d71(%rip), %rcx     # 0x207df
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xafad
movzwl 0x10(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movzwl 0x12(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x11, %esi
callq 0xa29c
testq %rax, %rax
je 0xaade
movl 0x3(%rax), %edi
callq 0xef64
xorl %ecx, %ecx
cmpl $0x2, %eax
sete %cl
movl %ecx, 0x11a(%rbx)
movl %ecx, 0x1f81a(%rip)     # 0x2a2f8
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x16, %esi
callq 0xa29c
testq %rax, %rax
je 0xab5d
cmpl $0x0, 0x10a(%rbx)
je 0xab5d
movl 0x3(%rax), %edi
callq 0xef64
movl %eax, 0x14(%rsp)
movq 0x1f4af(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movl 0x14(%rsp), %ecx
leaq 0x15ccd(%rip), %rsi     # 0x207f1
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x20170(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xab5d
callq 0xeb2f
movl 0x14(%rsp), %ecx
leaq 0x15ca1(%rip), %rsi     # 0x207f1
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x0, 0x24(%rsp)
je 0xad12
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x17, %esi
callq 0xa29c
testq %rax, %rax
je 0xabf8
movq %rax, %r14
movl 0x24(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xef64
cmpl %eax, %ebp
jae 0xab98
movl 0x24(%rsp), %eax
jmp 0xaba1
movl 0x3(%r14), %edi
callq 0xef64
movl %eax, 0x24(%rsp)
movq 0x1f414(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movl 0x24(%rsp), %ecx
leaq 0x15c57(%rip), %rsi     # 0x20816
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x200d5(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xabf8
callq 0xeb2f
movl 0x24(%rsp), %ecx
leaq 0x15c2b(%rip), %rsi     # 0x20816
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x18, %esi
callq 0xa29c
testq %rax, %rax
je 0xac88
movq %rax, %r14
movl 0x28(%rsp), %ebp
movl 0x3(%rax), %edi
callq 0xef64
cmpl %eax, %ebp
jae 0xac28
movl 0x28(%rsp), %eax
jmp 0xac31
movl 0x3(%r14), %edi
callq 0xef64
movl %eax, 0x28(%rsp)
movq 0x1f384(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movl 0x28(%rsp), %ecx
leaq 0x15c03(%rip), %rsi     # 0x20852
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x20045(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xac88
callq 0xeb2f
movl 0x28(%rsp), %ecx
leaq 0x15bd7(%rip), %rsi     # 0x20852
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movq (%rsp), %rdi
addq $0x9, %rdi
movl $0x1a, %esi
callq 0xa29c
testq %rax, %rax
je 0xacfe
movl 0x3(%rax), %edi
callq 0xef64
movl %eax, 0x2c(%rsp)
movq 0x1f30e(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movl 0x2c(%rsp), %ecx
leaq 0x15bc9(%rip), %rsi     # 0x2088e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1ffcf(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0xacfe
callq 0xeb2f
movl 0x2c(%rsp), %ecx
leaq 0x15b9d(%rip), %rsi     # 0x2088e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
cmpl $0x2, 0x24(%rsp)
jb 0xad12
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xf792
movq (%rsp), %rdi
callq 0x5040
cmpb $0x0, 0x50(%rbx)
je 0xadfd
cmpb $0x0, 0xca(%rbx)
je 0xadb8
leaq 0x303b(%rip), %rdx      # 0xdd74
leaq 0x10(%rsp), %rcx
movl $0x1, %edi
movl $0xa2, %esi
callq 0xda86
leaq 0x15a8b(%rip), %rcx     # 0x207df
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%r14), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xaa1b
movzwl 0x10(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movzwl 0x12(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xadb8
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x4, (%rcx)
leaq 0x3025(%rip), %rdx      # 0xddec
movl $0x1, %edi
movl $0x4d, %esi
callq 0xda86
leaq 0x15a02(%rip), %rcx     # 0x207df
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movq (%r14), %rdi
testq %rdi, %rdi
je 0xadfd
callq 0x5040
cmpb $0x0, 0x51(%rbx)
je 0xafca
cmpb $0x0, 0xca(%rbx)
je 0xae9a
leaq 0x2f59(%rip), %rdx      # 0xdd74
leaq 0x10(%rsp), %rcx
movl $0x11, %edi
movl $0xa2, %esi
callq 0xda86
leaq 0x159a9(%rip), %rcx     # 0x207df
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xaa1b
movzwl 0x10(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movzwl 0x12(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xae9a
callq 0x5040
leaq 0xf(%rsp), %rcx
movb $0x6, (%rcx)
leaq 0x2f43(%rip), %rdx      # 0xddec
movl $0x11, %edi
movl $0x4d, %esi
callq 0xda86
leaq 0x15920(%rip), %rcx     # 0x207df
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movl %eax, %ebp
testl %eax, %eax
sets %al
movq (%rbx), %r12
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
je 0xaa1b
movzwl 0x10(%r12), %edi
callq 0xef61
testw %ax, %ax
jne 0xaf11
movzwl 0x12(%r12), %edi
callq 0xef61
testw %ax, %ax
je 0xafbc
movzwl 0x12(%r12), %edi
callq 0xef61
movl %eax, %ebx
movq 0x1f09b(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movq %rax, %r15
movzwl 0x10(%r12), %edi
callq 0xef61
movzwl %ax, %r8d
movzwl %bx, %ebp
leaq 0x1584e(%rip), %rsi     # 0x20797
leaq 0x1588f(%rip), %rcx     # 0x207df
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x1fd41(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xafa4
callq 0xeb2f
movq %rax, %r14
movzwl 0x10(%r12), %edi
callq 0xef61
movzwl %ax, %r8d
leaq 0x1580a(%rip), %rsi     # 0x20797
leaq 0x1584b(%rip), %rcx     # 0x207df
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 0xafca
callq 0x5040
leaq 0x2e4a(%rip), %rdx      # 0xde1b
leaq 0xe(%rsp), %rcx
movl $0x1, %edi
movl $0x51, %esi
callq 0xda86
leaq 0x157f3(%rip), %rcx     # 0x207df
movq %rsp, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
movq (%rbx), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
jne 0xafa8
jmp 0xafad