// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/atc.c
// Function: requestQueryDataCall
static int requestQueryDataCall(UCHAR  *pConnectionStatus, int curIpFamily) {
    int err;
    ATResponse *p_response = NULL;
    ATLine *p_cur = NULL;
    int state = 0;
    int bind = 0;
    int cid;
    int pdp = s_pdp;
    unsigned int v4Addr = 0;

    (void)curIpFamily;

    *pConnectionStatus = QWDS_PKT_DATA_DISCONNECTED;

    if (!asr_style_atc) {
        err = at_netdevstatus(pdp, &v4Addr);
        if (!err && v4Addr) {
            *pConnectionStatus = QWDS_PKT_DATA_CONNECTED;
            //if (profile->ipv4.Address == v4Addr) {} //TODO
        }
        return err;
    }

    err = at_send_command_multiline("AT+QNETDEVCTL?", "+QNETDEVCTL:", &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)
    {
        //+QNETDECTL:<op>,<cid>,<urc_en>,<state>
        err = at_tok_scanf(p_cur->line, "%d%d%d%d", &bind, &cid, NULL, &state);
        if (err != 4 || cid != pdp)
            continue;
        if (bind != 1)
            bind = 0;
    }
    safe_at_response_free(p_response);

    if (bind == 0 || state == 0)
        goto _error;

    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)
    {
        err = at_tok_scanf(p_cur->line, "%d%d", &cid, &state);
        if (err != 2 || cid != pdp)
            continue;
    }
    safe_at_response_free(p_response);

    if (bind && state)
        *pConnectionStatus = QWDS_PKT_DATA_CONNECTED;

_error:
    safe_at_response_free(p_response);
    //dbg_time("%s err=%d, call_state=%d", __func__, err, *pConnectionStatus);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x8(%rsp)
movl 0x12247(%rip), %ebp     # 0x2bf38
movl %eax, 0x1c(%rsp)
movb $0x1, (%rdi)
cmpb $0x0, 0x1223d(%rip)     # 0x2bf3c
je 0x19e91
leaq 0x955e(%rip), %rdi      # 0x2326a
leaq 0x9297(%rip), %rsi      # 0x22faa
leaq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x1b498
testl %eax, %eax
setne %cl
movq (%r14), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x19e77
cmpq $0x0, 0x8(%rax)
je 0x19e77
cmpl $0x0, (%rax)
je 0x19e77
movq %rbx, 0x20(%rsp)
movq 0x10(%rax), %rbx
testq %rbx, %rbx
je 0x19daa
leaq 0x965f(%rip), %r14      # 0x233be
leaq 0x8(%rsp), %r15
leaq 0x18(%rsp), %r12
leaq 0xc(%rsp), %r13
movq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0x1be91
cmpl $0x4, %eax
jne 0x19da2
cmpl %ebp, 0x18(%rsp)
jne 0x19da2
cmpl $0x1, 0x8(%rsp)
je 0x19da2
movl $0x0, 0x8(%rsp)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x19d6e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x19dc2
callq 0x1b2da
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x8(%rsp)
movq 0x20(%rsp), %r13
je 0x19e77
cmpl $0x0, 0xc(%rsp)
je 0x19e77
leaq 0x9417(%rip), %rdi      # 0x231fb
leaq 0x941a(%rip), %rsi      # 0x23205
leaq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x1b498
testl %eax, %eax
setne %cl
movq (%r14), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x19e77
cmpq $0x0, 0x8(%rax)
je 0x19e77
cmpl $0x0, (%rax)
je 0x19e77
movq 0x10(%rax), %rbx
testq %rbx, %rbx
je 0x19e4c
leaq 0x959c(%rip), %r14      # 0x233c2
leaq 0x18(%rsp), %r15
leaq 0xc(%rsp), %r12
movq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1be91
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x19e30
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x19e64
callq 0x1b2da
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0x19e77
cmpl $0x0, 0xc(%rsp)
je 0x19e77
movb $0x2, (%r13)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x19ea9
callq 0x1b2da
movq $0x0, 0x10(%rsp)
jmp 0x19ea9
leaq 0x1c(%rsp), %r14
movl %ebp, %edi
movq %r14, %rsi
callq 0x1aa08
cmpl $0x0, (%r14)
je 0x19ea9
movb $0x2, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq