// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, (%rsp)
andq $0x0, 0x8(%rsp)
movl 0x48(%rdi), %ebx
andl $0x0, 0x10(%rsp)
leaq 0x216(%rdi), %r15
leaq 0x8c8a(%rip), %rsi      # 0x2121e
movq %r15, %rdi
callq 0x1973c
testl %eax, %eax
jne 0x185b3
leaq 0x8c7e(%rip), %rsi      # 0x21225
movq %r15, %rdi
callq 0x1973c
testl %eax, %eax
je 0x185ee
addq $0xaa, %r14
leaq 0x8c6b(%rip), %rsi      # 0x2122c
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x53c0
movq (%r15), %rdi
callq 0x5170
movq (%r15), %rdi
testq %rdi, %rdi
je 0x185ee
callq 0x5040
andq $0x0, 0x8(%rsp)
cmpb $0x1, 0x12947(%rip)     # 0x2af3c
jne 0x186ad
leaq 0x8c39(%rip), %rdi      # 0x2123b
leaq 0x8c3c(%rip), %rsi      # 0x21245
movq %rsp, %r14
movq %r14, %rdx
callq 0x19ed7
movl %eax, %r15d
testl %eax, %eax
setne %al
movq (%r14), %r14
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1881c
xorl %r15d, %r15d
cmpq $0x0, 0x8(%r14)
je 0x18818
cmpl $0x0, (%r14)
je 0x18818
addq $0x10, %r14
leaq 0x8db2(%rip), %r15      # 0x21402
leaq 0x14(%rsp), %r12
leaq 0x10(%rsp), %r13
movq (%r14), %r14
testq %r14, %r14
je 0x1867d
andl $0x0, 0x14(%rsp)
movq 0x8(%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1a825
jmp 0x1865a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x18690
callq 0x19d1e
andq $0x0, (%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x187b2
cmpb $0x0, 0x1289a(%rip)     # 0x2af3c
je 0x186ad
leaq 0x8bb0(%rip), %rsi      # 0x2125b
jmp 0x186b4
leaq 0x8bbd(%rip), %rsi      # 0x21271
leaq 0x8(%rsp), %r14
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x53c0
movq (%r14), %rdi
movq %rsp, %rsi
callq 0x19d64
movl %eax, %r15d
movq (%r14), %rdi
testq %rdi, %rdi
je 0x186e9
callq 0x5040
andq $0x0, 0x8(%rsp)
testl %r15d, %r15d
setne %al
movq (%rsp), %r14
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1881c
xorl %r15d, %r15d
cmpq $0x0, 0x8(%r14)
je 0x18818
cmpl $0x0, (%r14)
je 0x18818
cmpb $0x0, 0x1281c(%rip)     # 0x2af3c
je 0x18731
movl $0x1005, %edi           # imm = 0x1005
callq 0x7244
jmp 0x18818
pushq $0xf
popq %r14
leaq 0x8b5f(%rip), %r12      # 0x2129b
movq %rsp, %r13
subl $0x1, %r14d
jb 0x18722
leaq 0x8(%rsp), %rdi
leaq 0x8b36(%rip), %rsi      # 0x21287
movl %ebx, %edx
xorl %eax, %eax
callq 0x53c0
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x19e06
movl %eax, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x18781
callq 0x5040
andq $0x0, 0x8(%rsp)
testl %ebp, %ebp
jne 0x18815
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x187a8
cmpq $0x0, 0x8(%rdi)
je 0x1879e
cmpl $0x0, (%rdi)
jne 0x18722
callq 0x19d1e
andq $0x0, (%rsp)
pushq $0x1
popq %rdi
callq 0x5550
jmp 0x1873f
leaq 0x8a94(%rip), %rsi      # 0x2124d
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x53c0
movq (%r14), %rdi
movq %rsp, %rsi
callq 0x19d64
movl %eax, %r15d
movq (%r14), %rdi
testq %rdi, %rdi
je 0x187eb
callq 0x5040
andq $0x0, 0x8(%rsp)
testl %r15d, %r15d
setne %al
movq (%rsp), %r14
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1881c
xorl %r15d, %r15d
cmpq $0x0, 0x8(%r14)
je 0x18818
cmpl $0x0, (%r14)
jne 0x1869b
jmp 0x18818
movl %ebp, %r15d
movq (%rsp), %r14
testq %r14, %r14
je 0x18829
movq %r14, %rdi
callq 0x19d1e
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq