// File: /workspace/github_c_makefile_star2_O3/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 0x9a9b(%rip), %rsi      # 0x231fe
movq %r15, %rdi
callq 0x1a978
testl %eax, %eax
jne 0x19782
leaq 0x9a8f(%rip), %rsi      # 0x23205
movq %r15, %rdi
callq 0x1a978
testl %eax, %eax
je 0x197c0
addq $0xaa, %r14
leaq 0x9a7c(%rip), %rsi      # 0x2320c
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 0x197c0
callq 0x5040
movq $0x0, 0x8(%rsp)
cmpb $0x1, 0x12775(%rip)     # 0x2bf3c
jne 0x19888
leaq 0x9a47(%rip), %rdi      # 0x2321b
leaq 0x9a4a(%rip), %rsi      # 0x23225
movq %rsp, %r15
movq %r15, %rdx
callq 0x1b08f
movl %eax, %r14d
testl %eax, %eax
setne %al
movq (%r15), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x19a05
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rdi)
je 0x19a01
cmpl $0x0, (%rdi)
je 0x19a01
movq 0x10(%rdi), %r13
testq %r13, %r13
je 0x1985e
leaq 0x9bbc(%rip), %r14      # 0x233e2
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 0x1bb39
movq (%r13), %r13
testq %r13, %r13
jne 0x19830
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1986b
callq 0x1aeb5
movq $0x0, (%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x19999
cmpb $0x0, 0x126bf(%rip)     # 0x2bf3c
je 0x19888
leaq 0x99b5(%rip), %rsi      # 0x2323b
jmp 0x1988f
leaq 0x99c2(%rip), %rsi      # 0x23251
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movl %ebx, %edx
movl $0x1, %ecx
xorl %eax, %eax
callq 0x53b0
movq (%r15), %rdi
movq %rsp, %rsi
callq 0x1aefe
movl %eax, %r14d
movq (%r15), %rdi
testq %rdi, %rdi
je 0x198c9
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %r14d, %r14d
setne %al
movq (%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x19a05
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rdi)
je 0x19a01
cmpl $0x0, (%rdi)
je 0x19a01
cmpb $0x0, 0x1263d(%rip)     # 0x2bf3c
jne 0x1998d
movl $0xf, %r15d
leaq 0x9969(%rip), %r12      # 0x2327b
movq %rsp, %r13
leaq 0x8(%rsp), %rdi
leaq 0x9946(%rip), %rsi      # 0x23267
movl %ebx, %edx
xorl %eax, %eax
callq 0x53b0
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1afa9
movl %eax, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x19954
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %ebp, %ebp
jne 0x199fe
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1997e
cmpq $0x0, 0x8(%rdi)
je 0x19971
cmpl $0x0, (%rdi)
jne 0x1998d
callq 0x1aeb5
movq $0x0, (%rsp)
movl $0x1, %edi
callq 0x5540
decl %r15d
jne 0x19915
movl $0x1005, %edi           # imm = 0x1005
callq 0x7354
jmp 0x19a01
leaq 0x988d(%rip), %rsi      # 0x2322d
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x53b0
movq (%r15), %rdi
movq %rsp, %rsi
callq 0x1aefe
movl %eax, %r14d
movq (%r15), %rdi
testq %rdi, %rdi
je 0x199d5
callq 0x5040
movq $0x0, 0x8(%rsp)
testl %r14d, %r14d
setne %al
movq (%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x19a05
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rdi)
je 0x19a01
cmpl $0x0, (%rdi)
jne 0x19876
jmp 0x19a01
movl %ebp, %r14d
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x19a0f
callq 0x1aeb5
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq