// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/QMIThread.c
// Function: WdsStartNwInterfaceReq
static USHORT WdsStartNwInterfaceReq(PQMUX_MSG pMUXMsg, void *arg) {
    PQMIWDS_TECHNOLOGY_PREFERECE pTechPref;
    PQMIWDS_AUTH_PREFERENCE pAuthPref;
    PQMIWDS_USERNAME pUserName;
    PQMIWDS_PASSWD pPasswd;
    PQMIWDS_APNNAME pApnName;
    PQMIWDS_IP_FAMILY_TLV pIpFamily;
    USHORT TLVLength = 0;
    UCHAR *pTLV;
    PROFILE_T *profile = (PROFILE_T *)arg;
    const char *profile_user = profile->user;
    const char *profile_password = profile->password;
    int profile_auth = profile->auth;

    if (s_is_cdma && (profile_user == NULL || profile_user[0] == '\0') && (profile_password == NULL || profile_password[0] == '\0')) {
        profile_user = "ctnet@mycdma.cn";
        profile_password = "vnet.mobi";
        profile_auth = 2; //chap
    }

    pTLV = (UCHAR *)(&pMUXMsg->StartNwInterfaceReq + 1);
    pMUXMsg->StartNwInterfaceReq.Length = 0;

    // Set technology Preferece
    pTechPref = (PQMIWDS_TECHNOLOGY_PREFERECE)(pTLV + TLVLength);
    pTechPref->TLVType = 0x30;
    pTechPref->TLVLength = cpu_to_le16(0x01);
    if (s_is_cdma == 0)
        pTechPref->TechPreference = 0x01;
    else
        pTechPref->TechPreference = 0x02;
    TLVLength +=(le16_to_cpu(pTechPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));

    // Set APN Name
    if (profile->apn && !s_is_cdma) { //cdma no apn
        pApnName = (PQMIWDS_APNNAME)(pTLV + TLVLength);
        pApnName->TLVType = 0x14;
        pApnName->TLVLength = cpu_to_le16(strlen(profile->apn));
        qstrcpy((char *)&pApnName->ApnName, profile->apn);
        TLVLength +=(le16_to_cpu(pApnName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set User Name
    if (profile_user) {
        pUserName = (PQMIWDS_USERNAME)(pTLV + TLVLength);
        pUserName->TLVType = 0x17;
        pUserName->TLVLength = cpu_to_le16(strlen(profile_user));
        qstrcpy((char *)&pUserName->UserName, profile_user);
        TLVLength += (le16_to_cpu(pUserName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set Password
    if (profile_password) {
        pPasswd = (PQMIWDS_PASSWD)(pTLV + TLVLength);
        pPasswd->TLVType = 0x18;
        pPasswd->TLVLength = cpu_to_le16(strlen(profile_password));
        qstrcpy((char *)&pPasswd->Passwd, profile_password);
	TLVLength += (le16_to_cpu(pPasswd->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set Auth Protocol
    if (profile_user && profile_password) {
        pAuthPref = (PQMIWDS_AUTH_PREFERENCE)(pTLV + TLVLength);
        pAuthPref->TLVType = 0x16;
        pAuthPref->TLVLength = cpu_to_le16(0x01);
        pAuthPref->AuthPreference = profile_auth; // 0 ~ None, 1 ~ Pap, 2 ~ Chap, 3 ~ MsChapV2
        TLVLength += (le16_to_cpu(pAuthPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Add IP Family Preference
    pIpFamily = (PQMIWDS_IP_FAMILY_TLV)(pTLV + TLVLength);
    pIpFamily->TLVType = 0x19;
    pIpFamily->TLVLength = cpu_to_le16(0x01);
    pIpFamily->IpFamily = profile->curIpFamily;
    TLVLength += (le16_to_cpu(pIpFamily->TLVLength) + sizeof(QCQMICTL_TLV_HDR));

    //Set Profile Index
    if (profile->pdp && !s_is_cdma) { //cdma only support one pdp, so no need to set profile index
        PQMIWDS_PROFILE_IDENTIFIER pProfileIndex = (PQMIWDS_PROFILE_IDENTIFIER)(pTLV + TLVLength);
        pProfileIndex->TLVLength = cpu_to_le16(0x01);
        pProfileIndex->TLVType = 0x31;
        pProfileIndex->ProfileIndex = profile->pdp;
        if (s_is_cdma && s_hdr_personality == 0x02) {
            pProfileIndex->TLVType = 0x32; //profile_index_3gpp2
            pProfileIndex->ProfileIndex = 101;
        }
        TLVLength += (le16_to_cpu(pProfileIndex->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    return sizeof(QMIWDS_START_NETWORK_INTERFACE_REQ_MSG) + TLVLength;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x42(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, 0x24b9a(%rip)     # 0x37df4
je 0x1329f
cmpq $0x0, -0x60(%rbp)
je 0x1326f
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1329f
cmpq $0x0, -0x68(%rbp)
je 0x13282
movq -0x68(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1329f
leaq 0x1ab61(%rip), %rax     # 0x2ddea
movq %rax, -0x60(%rbp)
leaq 0x1ab66(%rip), %rax     # 0x2ddfa
movq %rax, -0x68(%rbp)
movl $0x2, -0x6c(%rbp)
movq -0x8(%rbp), %rax
addq $0x3, %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movw $0x0, 0x5(%rax)
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $0x30, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1(%rax)
cmpl $0x0, 0x24b06(%rip)     # 0x37df4
jne 0x132fa
movq -0x18(%rbp), %rax
movb $0x1, 0x3(%rax)
jmp 0x13302
movq -0x18(%rbp), %rax
movb $0x2, 0x3(%rax)
movq -0x18(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
movq -0x58(%rbp), %rax
cmpq $0x0, (%rax)
je 0x133a3
cmpl $0x0, 0x24ac0(%rip)     # 0x37df4
jne 0x133a3
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x14, (%rax)
movq -0x58(%rbp), %rax
movq (%rax), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x38(%rbp), %rdi
addq $0x3, %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rsi
callq 0x11cb0
movq -0x38(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x13411
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb $0x17, (%rax)
movq -0x60(%rbp), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x28(%rbp), %rdi
addq $0x3, %rdi
movq -0x60(%rbp), %rsi
callq 0x11cb0
movq -0x28(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1347f
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb $0x18, (%rax)
movq -0x68(%rbp), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x30(%rbp), %rdi
addq $0x3, %rdi
movq -0x68(%rbp), %rsi
callq 0x11cb0
movq -0x30(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x134e8
cmpq $0x0, -0x68(%rbp)
je 0x134e8
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movb $0x16, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x1(%rax)
movl -0x6c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x20(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x19, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x58(%rbp), %rax
movl 0x116(%rax), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x40(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x48(%rax)
je 0x135e5
cmpl $0x0, 0x24895(%rip)     # 0x37df4
jne 0x135e5
movq -0x50(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x78(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x78(%rbp), %rax
movb $0x31, (%rax)
movq -0x58(%rbp), %rax
movl 0x48(%rax), %eax
movb %al, %cl
movq -0x78(%rbp), %rax
movb %cl, 0x3(%rax)
cmpl $0x0, 0x2484a(%rip)     # 0x37df4
je 0x135c4
cmpl $0x2, 0x24845(%rip)     # 0x37df8
jne 0x135c4
movq -0x78(%rbp), %rax
movb $0x32, (%rax)
movq -0x78(%rbp), %rax
movb $0x65, 0x3(%rax)
movq -0x78(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x42(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x42(%rbp)
movzwl -0x42(%rbp), %eax
addq $0x4, %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)