// File: goodix[P]gdix_hid_firmware_update/gtx2/gtx2.cpp
// Function: GTx2Device::SetBasicProperties()
int GTx2Device::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[12] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 2;
	unsigned char cfg_ver = 0;
	int retry = 10;

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}

	do {
		ret = Read(0x8050, &cfg_ver, 1);
		if (ret < 0) {
			gdix_dbg("Failed read cfg VERSION, retry=%d\n", retry);
			continue;
		}

		ret = Read(0x8140, fw_info, sizeof(fw_info));
		if (ret < 0)
			gdix_dbg("Failed read VERSION, retry=%d\n", retry);
		else
			break;
	} while (--retry);

	if (!retry)
		return -1;

	memcpy(m_pid, fw_info, 4);
	m_pid[4] = '\0';
	gdix_dbg("pid:%s\n", m_pid);
	m_sensorID = fw_info[10] & 0x0f;
	gdix_dbg("sensorID:%d\n", m_sensorID);

	if (!memcmp(m_pid, "7288", 4)) {
		m_firmwareVersionMajor = fw_info[5];
		m_firmwareVersionMinor = ((fw_info[6] << 16) | (0x00) << 8) | cfg_ver;
	} else {
		m_firmwareVersionMajor = fw_info[4];
		m_firmwareVersionMinor =
			((fw_info[5] << 16) | (fw_info[6]) << 8) | cfg_ver;
	}

	gdix_dbg("cfg version:%d\n", cfg_ver);
	gdix_dbg("version:0x%x,0x%x\n", m_firmwareVersionMajor,
			 m_firmwareVersionMinor);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x50a0
movq -0x30(%rbp), %rax
movl $0x14, 0x10(%rax)
movl $0x14, 0x14(%rax)
movl $0x2, 0x18(%rax)
movb $0x0, -0x21(%rbp)
movl $0xa, -0x28(%rbp)
testb $0x1, 0x8(%rax)
jne 0xaaee
jmp 0xaab0
leaq 0x1b7e2(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xaae0
movq 0x1b515(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x121b2(%rip), %rsi     # 0x1cc7f
leaq 0x121d6(%rip), %rdx     # 0x1ccaa
movl $0x31, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xaae2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xad3c
jmp 0xaaf0
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movl $0x8050, %esi           # imm = 0x8050
leaq -0x21(%rbp), %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0xab4b
jmp 0xab13
leaq 0x1b77f(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xab47
movq 0x1b492(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x28(%rbp), %r8d
leaq 0x121ec(%rip), %rsi     # 0x1cd20
leaq 0x1216f(%rip), %rdx     # 0x1ccaa
movl $0x38, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xab49
jmp 0xabaa
movq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rdx
movq (%rdi), %rax
movl $0x8140, %esi           # imm = 0x8140
movl $0xc, %ecx
callq *0x20(%rax)
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0xaba6
jmp 0xab6e
leaq 0x1b724(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xaba2
movq 0x1b437(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x28(%rbp), %r8d
leaq 0x121e2(%rip), %rsi     # 0x1cd71
leaq 0x12114(%rip), %rdx     # 0x1ccaa
movl $0x3e, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xaba4
jmp 0xaba8
jmp 0xabbc
jmp 0xabaa
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jne 0xaaf0
cmpl $0x0, -0x28(%rbp)
jne 0xabce
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xad3c
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, 0x1c(%rax)
movb $0x0, 0x20(%rax)
leaq 0x1b6b6(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xac14
movq -0x30(%rbp), %r8
movq 0x1b3c5(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
addq $0x1c, %r8
leaq 0x1226e(%rip), %rsi     # 0x1ce6f
leaq 0x120a2(%rip), %rdx     # 0x1ccaa
movl $0x48, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xac16
movq -0x30(%rbp), %rax
movzbl -0x16(%rbp), %ecx
andl $0xf, %ecx
movl %ecx, 0x18(%rax)
leaq 0x1b66e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xac5c
movq -0x30(%rbp), %rax
movq 0x1b37d(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x18(%rax), %r8d
leaq 0x1223f(%rip), %rsi     # 0x1ce88
leaq 0x1205a(%rip), %rdx     # 0x1ccaa
movl $0x4a, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xac5e
movq -0x30(%rbp), %rax
addq $0x1c, %rax
movl (%rax), %eax
subl $0x38383237, %eax       # imm = 0x38383237
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xac98
movq -0x30(%rbp), %rax
movzbl -0x1b(%rbp), %ecx
movl %ecx, 0x10(%rax)
movzbl -0x1a(%rbp), %ecx
shll $0x10, %ecx
orl $0x0, %ecx
movzbl -0x21(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0xacbc
movq -0x30(%rbp), %rax
movzbl -0x1c(%rbp), %ecx
movl %ecx, 0x10(%rax)
movzbl -0x1b(%rbp), %ecx
shll $0x10, %ecx
movzbl -0x1a(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
movzbl -0x21(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0xacbe
leaq 0x1b5d4(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xacf3
movq 0x1b2e7(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x21(%rbp), %r8d
leaq 0x12ea1(%rip), %rsi     # 0x1db81
leaq 0x11fc3(%rip), %rdx     # 0x1ccaa
movl $0x55, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xacf5
jmp 0xacf7
leaq 0x1b59b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xad33
movq -0x30(%rbp), %rax
movq 0x1b2aa(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
leaq 0x12186(%rip), %rsi     # 0x1cea6
leaq 0x11f83(%rip), %rdx     # 0x1ccaa
movl $0x57, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xad35
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)