// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/atc.c
// Function: requestSetupDataCall
static int requestSetupDataCall(PROFILE_T *profile, int curIpFamily) {
    int err;
    ATResponse *p_response = NULL;
    char *cmd = NULL;
    ATLine *p_cur = NULL;
    int pdp = profile->pdp;
    int state = 0;

    (void)curIpFamily;

    if (strStartsWith(profile->BaseBandVersion, "RG801H") || strStartsWith(profile->BaseBandVersion, "EC200H")) {
        //RG801H will miss USB_CDC_NOTIFY_NETWORK_CONNECTION
        asprintf(&cmd, "ifconfig %s up", profile->usbnet_adapter);
        if (system(cmd)) {};
        safe_free(cmd);
    }

    if (asr_style_atc) {
        err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &p_response);
        if (at_response_error(err, p_response))
            goto _error;

        for (p_cur = p_response->p_intermediates; p_cur != NULL; p_cur = p_cur->p_next) {
            int cid = 0;

            err = at_tok_scanf(p_cur->line, "%d%d", &cid, &state);
            if (err != 2 || cid != pdp)
                continue;
        }
        safe_at_response_free(p_response);

        if (state == 0) {
            asprintf(&cmd, "AT+CGACT=1,%d", pdp);
            err = at_send_command(cmd, &p_response);
            safe_free(cmd);
            if (at_response_error(err, p_response))
                goto _error;
        }
    }

    if(asr_style_atc)
        asprintf(&cmd, "AT+QNETDEVCTL=1,%d,%d", pdp, 1);
    else
        asprintf(&cmd, "AT+QNETDEVCTL=%d,1,%d", pdp, 1);
    err = at_send_command(cmd, &p_response);
    safe_free(cmd);

    if (at_response_error(err, p_response))
        goto _error;

    if (!asr_style_atc) { //TODO some modems do not sync return setup call resule
        int t = 0;

        while (t++ < 15) {
            asprintf(&cmd, "AT+QNETDEVSTATUS=%d", pdp);
            err = at_send_command_singleline(cmd, "+QNETDEVSTATUS", &p_response);
            safe_free(cmd);
            if (err) goto _error;

            if (!at_response_error(err, p_response)) {
                break;
            }
            safe_at_response_free(p_response);
            sleep(1);
        }
    }

    //some modem do not report URC
    qmidevice_send_event_to_main(RIL_UNSOL_DATA_CALL_LIST_CHANGED);

_error:
    safe_at_response_free(p_response);
    //dbg_time("%s err=%d", __func__, err);
    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
xorl %eax, %eax
movq %rax, (%rsp)
movq %rax, 0x8(%rsp)
movl 0x48(%rdi), %ebx
movl $0x0, 0x10(%rsp)
leaq 0x216(%rdi), %r15
leaq 0x97e5(%rip), %rsi      # 0x231de
movq %r15, %rdi
callq 0x1abfc
testl %eax, %eax
jne 0x19a18
leaq 0x97d9(%rip), %rsi      # 0x231e5
movq %r15, %rdi
callq 0x1abfc
testl %eax, %eax
je 0x19a56
addq $0xaa, %r14
leaq 0x97c6(%rip), %rsi      # 0x231ec
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x53b0
movq (%r15), %rdi
callq 0x5170
movq (%r15), %rdi
testq %rdi, %rdi
je 0x19a56
callq 0x5040
movq $0x0, 0x8(%rsp)
cmpb $0x1, 0x124df(%rip)     # 0x2bf3c
jne 0x19b0a
leaq 0x9791(%rip), %rdi      # 0x231fb
leaq 0x9794(%rip), %rsi      # 0x23205
movq %rsp, %r14
movq %r14, %rdx
callq 0x1b498
movl %eax, %ebp
testl %eax, %eax
setne %cl
movq (%r14), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x19ca0
xorl %ebp, %ebp
cmpq $0x0, 0x8(%rax)
je 0x19ca0
cmpl $0x0, (%rax)
je 0x19ca0
movq 0x10(%rax), %r13
testq %r13, %r13
je 0x19ae9
leaq 0x9908(%rip), %r14      # 0x233c2
leaq 0x14(%rsp), %r15
leaq 0x10(%rsp), %r12
movl $0x0, 0x14(%rsp)
movq 0x8(%r13), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1be91
movq (%r13), %r13
testq %r13, %r13
jne 0x19ac4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19aff
callq 0x1b2da
movq $0x0, (%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x19c2c
leaq 0x970a(%rip), %rax      # 0x2321b
leaq 0x9719(%rip), %rsi      # 0x23231
cmpb $0x0, 0x1241d(%rip)     # 0x2bf3c
cmovneq %rax, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
movl $0x1, %ecx
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
movq %rsp, %rsi
callq 0x1b323
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19b5c
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %ebp, %ebp
setne %cl
movq (%rsp), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x19ca0
xorl %ebp, %ebp
cmpq $0x0, 0x8(%rax)
je 0x19ca0
cmpl $0x0, (%rax)
je 0x19ca0
xorl %ebp, %ebp
cmpb $0x0, 0x123aa(%rip)     # 0x2bf3c
jne 0x19c96
movl $0xf, %ebp
leaq 0x8(%rsp), %r15
leaq 0x96b2(%rip), %r12      # 0x2325b
movq %rsp, %r13
movq %r15, %rdi
leaq 0x9691(%rip), %rsi      # 0x23247
movl %ebx, %edx
xorl %eax, %eax
callq 0x53b0
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1b3c6
movl %eax, %r14d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x19bea
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %r14d, %r14d
jne 0x19c8e
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19c1a
cmpq $0x0, 0x8(%rdi)
je 0x19c08
cmpl $0x0, (%rdi)
jne 0x19c28
testq %rdi, %rdi
je 0x19c1a
callq 0x1b2da
movq $0x0, (%rsp)
movl $0x1, %edi
callq 0x5540
decl %ebp
jne 0x19bac
xorl %ebp, %ebp
jmp 0x19c91
leaq 0x95da(%rip), %rsi      # 0x2320d
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
movq %rsp, %rsi
callq 0x1b323
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19c67
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %ebp, %ebp
setne %cl
movq (%rsp), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x19ca0
xorl %ebp, %ebp
cmpq $0x0, 0x8(%rax)
je 0x19ca0
cmpl $0x0, (%rax)
jne 0x19b0a
jmp 0x19ca0
movl %r14d, %ebp
testl %r14d, %r14d
jne 0x19ca0
movl $0x1005, %edi           # imm = 0x1005
callq 0x7444
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19cb6
callq 0x1b2da
movq $0x0, (%rsp)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq