// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/QmiWwanCM.c
// Function: QmiWwanInit
static int QmiWwanInit(PROFILE_T *profile) {
    unsigned i;
    int ret;
    PQCQMIMSG pResponse;

    if (profile->proxy[0] && !strcmp(profile->proxy, LIBQMI_PROXY)) {
        ret = libqmi_proxy_open(profile->qmichannel);
        if (ret)
            return ret;
    }

    if (!profile->proxy[0]) {
        for (i = 0; i < 10; i++) {
            ret = QmiThreadSendQMITimeout(ComposeQCTLMsg(QMICTL_SYNC_REQ, NULL, NULL), NULL, 1 * 1000, __func__);
            if (!ret)
                break;
            sleep(1);
        }
        if (ret)
            return ret;
    }

    QmiThreadSendQMI(ComposeQCTLMsg(QMICTL_GET_VERSION_REQ, CtlGetVersionReq, NULL), &pResponse);
    if (profile->qmap_mode) {
        if (pResponse) {
            if (pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXResult == 0 && pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXError == 0) {
                uint8_t  NumElements = 0;

                for (NumElements = 0; NumElements < pResponse->CTLMsg.GetVersionRsp.NumElements; NumElements++) {
#if 0
                    dbg_time("QMUXType = %02x Version = %d.%d",
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].QMUXType,
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MajorVersion,
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MinorVersion);
#endif
                    if (pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].QMUXType == QMUX_TYPE_WDS_ADMIN)
                        profile->qmap_version = (pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MinorVersion > 16);
                }
            }
        }
    }
    if (pResponse) free(pResponse);
    qmiclientId[QMUX_TYPE_WDS] = QmiWwanGetClientID(QMUX_TYPE_WDS);
    if (profile->enable_ipv6)
        qmiclientId[QMUX_TYPE_WDS_IPV6] = QmiWwanGetClientID(QMUX_TYPE_WDS);
    qmiclientId[QMUX_TYPE_DMS] = QmiWwanGetClientID(QMUX_TYPE_DMS);
    qmiclientId[QMUX_TYPE_NAS] = QmiWwanGetClientID(QMUX_TYPE_NAS);
    qmiclientId[QMUX_TYPE_UIM] = QmiWwanGetClientID(QMUX_TYPE_UIM);
    qmiclientId[QMUX_TYPE_WDS_ADMIN] = QmiWwanGetClientID(QMUX_TYPE_WDS_ADMIN);
    profile->wda_client = qmiclientId[QMUX_TYPE_WDS_ADMIN];

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x0, 0x28(%rdi)
je 0x5857
leaq 0x28(%rbx), %r14
leaq 0x16a3a(%rip), %rsi     # 0x1c119
movq %r14, %rdi
callq 0x52a0
testl %eax, %eax
je 0x57b6
leaq 0xf6f(%rip), %rsi       # 0x6665
pushq $0x21
popq %rdi
xorl %edx, %edx
callq 0x6553
leaq 0x16929(%rip), %rcx     # 0x1c030
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
cmpl $0x0, 0x10a(%rbx)
setne %al
movq (%r14), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5746
cmpw $0x0, 0xf(%rdi)
jne 0x5746
cmpw $0x0, 0x11(%rdi)
je 0x5814
callq 0x5040
pushq $0x1
popq %rdi
callq 0x6225
movb %al, 0x23be8(%rip)      # 0x29341
cmpb $0x0, 0x51(%rbx)
je 0x576d
pushq $0x1
popq %rdi
callq 0x6225
movb %al, 0x23be4(%rip)      # 0x29351
pushq $0x2
popq %rdi
callq 0x6225
movb %al, 0x23bc7(%rip)      # 0x29342
pushq $0x3
popq %rdi
callq 0x6225
movb %al, 0x23bba(%rip)      # 0x29343
pushq $0xb
popq %rdi
callq 0x6225
movb %al, 0x23bb4(%rip)      # 0x2934b
pushq $0x1a
popq %rdi
callq 0x6225
movb %al, 0x23bb5(%rip)      # 0x2935a
movzbl %al, %eax
movl %eax, 0x122(%rbx)
xorl %r15d, %r15d
jmp 0x58ad
leaq 0x8a(%rbx), %rdx
leaq 0xebf(%rip), %rsi       # 0x6683
movl $0xff00, %edi           # imm = 0xFF00
callq 0x6553
leaq 0x16867(%rip), %rcx     # 0x1c03c
movq %rsp, %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x9e8b
testl %eax, %eax
sete %al
movq (%r15), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x580b
cmpw $0x0, 0xf(%rdi)
jne 0x580b
cmpw $0x0, 0x11(%rdi)
je 0x5848
pushq $-0x1
popq %r15
jmp 0x58ad
movq %rdi, %rax
addq $0x1a, %rax
xorl %ecx, %ecx
movzbl 0x16(%rdi), %edx
cmpq %rdx, %rcx
jae 0x5746
cmpb $0x1a, -0x3(%rax)
jne 0x583f
xorl %edx, %edx
cmpw $0x11, (%rax)
setae %dl
movl %edx, 0x112(%rbx)
incq %rcx
addq $0x5, %rax
jmp 0x581d
callq 0x5040
cmpb $0x0, (%r14)
jne 0x56ef
xorl %r15d, %r15d
pushq $0xa
popq %r13
pushq $0x27
popq %rbp
leaq 0x167c8(%rip), %r14     # 0x1c030
pushq $0x1
popq %r12
subl $0x1, %r13d
jb 0x58a4
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6553
movq %rax, %rdi
xorl %esi, %esi
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rcx
callq 0x9e8b
testl %eax, %eax
je 0x56ef
movl %eax, %r15d
movl %r12d, %edi
callq 0x5550
jmp 0x586c
testl %r15d, %r15d
je 0x56ef
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq