// File: goodix[P]gdix_hid_firmware_update/gtx8/gtx8.cpp
// Function: GTx8Device::SetBasicProperties()
int GTx8Device::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[72] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 0xF;
	unsigned char cfg_ver = 0;
	int retry = 10;
	unsigned char chksum;

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}
	do {
		ret = Read(CFG_START_ADDR, &cfg_ver, 1);
		if (ret < 0) {
			gdix_dbg("Failed read cfg VERSION, retry=%d\n", retry);
			continue;
		}
		gdix_dbg("cfg ver:%d\n", cfg_ver);
		ret = Read(VER_ADDR, fw_info, sizeof(fw_info));
		if (ret < 0)
			gdix_dbg("Failed read VERSION, retry=%d\n", retry);
		else
			break;
	} while (--retry);
	gdix_dbg("Fw_info array\n");
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[0], fw_info[1],
			 fw_info[2], fw_info[3], fw_info[4]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[5],
			 fw_info[6], fw_info[7], fw_info[8], fw_info[9], fw_info[10]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[11],
			 fw_info[12], fw_info[13], fw_info[14], fw_info[15], fw_info[16]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[17], fw_info[18],
			 fw_info[19], fw_info[20], fw_info[21]);
	if (!retry)
		return -1;

	/*check fw version*/
	chksum = ChecksumU8(fw_info, sizeof(fw_info));
	if (chksum) {
		gdix_err("fw version check sum error:%d\n", chksum);
		return -2;
	}

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

	m_firmwareVersionMajor = fw_info[18];
	m_firmwareVersionMinor =
		((fw_info[19] << 16) | (fw_info[20]) << 8) | cfg_ver;

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

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xa8, %rsp
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x50a0
movq -0x88(%rbp), %rax
movl $0x14, 0x10(%rax)
movl $0x14, 0x14(%rax)
movl $0xf, 0x18(%rax)
movb $0x0, -0x71(%rbp)
movl $0xa, -0x78(%rbp)
testb $0x1, 0x8(%rax)
jne 0x10d38
jmp 0x10cfa
leaq 0x15598(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10d2a
movq 0x152cb(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xbf68(%rip), %rsi      # 0x1cc7f
leaq 0xbf8c(%rip), %rdx      # 0x1ccaa
movl $0x27, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x10d2c
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x11170
jmp 0x10d3a
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movl $0x60dc, %esi           # imm = 0x60DC
leaq -0x71(%rbp), %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x10d9b
jmp 0x10d60
leaq 0x15532(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10d94
movq 0x15245(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x78(%rbp), %r8d
leaq 0xbf9f(%rip), %rsi      # 0x1cd20
leaq 0xbf22(%rip), %rdx      # 0x1ccaa
movl $0x2d, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x10d96
jmp 0x10e36
jmp 0x10d9d
leaq 0x154f5(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10dd2
movq 0x15208(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x71(%rbp), %r8d
leaq 0xbf95(%rip), %rsi      # 0x1cd54
leaq 0xbee4(%rip), %rdx      # 0x1ccaa
movl $0x30, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x10dd4
movq -0x88(%rbp), %rdi
leaq -0x70(%rbp), %rdx
movq (%rdi), %rax
movl $0x452c, %esi           # imm = 0x452C
movl $0x48, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x10e32
jmp 0x10dfa
leaq 0x15498(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10e2e
movq 0x151ab(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x78(%rbp), %r8d
leaq 0xbf56(%rip), %rsi      # 0x1cd71
leaq 0xbe88(%rip), %rdx      # 0x1ccaa
movl $0x33, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x10e30
jmp 0x10e34
jmp 0x10e48
jmp 0x10e36
movl -0x78(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, %eax
jne 0x10d3a
jmp 0x10e4a
leaq 0x15448(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10e7a
movq 0x1515b(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xbf3a(%rip), %rsi      # 0x1cda1
leaq 0xbe3c(%rip), %rdx      # 0x1ccaa
movl $0x37, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x10e7c
jmp 0x10e7e
leaq 0x15414(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10ed3
movq 0x15127(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x70(%rbp), %r8d
movzbl -0x6f(%rbp), %r9d
movzbl -0x6e(%rbp), %r11d
movzbl -0x6d(%rbp), %r10d
movzbl -0x6c(%rbp), %eax
leaq 0xbf0e(%rip), %rsi      # 0x1cdc1
leaq 0xbdf0(%rip), %rdx      # 0x1ccaa
movl $0x39, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x10ed5
jmp 0x10ed7
leaq 0x153bb(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10f34
movq 0x150ce(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x6b(%rbp), %r8d
movzbl -0x6a(%rbp), %r9d
movzbl -0x69(%rbp), %ebx
movzbl -0x68(%rbp), %r11d
movzbl -0x67(%rbp), %r10d
movzbl -0x66(%rbp), %eax
leaq 0xbee6(%rip), %rsi      # 0x1cdf6
leaq 0xbd93(%rip), %rdx      # 0x1ccaa
movl $0x3b, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x10f36
jmp 0x10f38
leaq 0x1535a(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10f95
movq 0x1506d(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x65(%rbp), %r8d
movzbl -0x64(%rbp), %r9d
movzbl -0x63(%rbp), %ebx
movzbl -0x62(%rbp), %r11d
movzbl -0x61(%rbp), %r10d
movzbl -0x60(%rbp), %eax
leaq 0xbe85(%rip), %rsi      # 0x1cdf6
leaq 0xbd32(%rip), %rdx      # 0x1ccaa
movl $0x3d, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x10f97
jmp 0x10f99
leaq 0x152f9(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x10fee
movq 0x1500c(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x5f(%rbp), %r8d
movzbl -0x5e(%rbp), %r9d
movzbl -0x5d(%rbp), %r11d
movzbl -0x5c(%rbp), %r10d
movzbl -0x5b(%rbp), %eax
leaq 0xbdf3(%rip), %rsi      # 0x1cdc1
leaq 0xbcd5(%rip), %rdx      # 0x1ccaa
movl $0x3f, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x10ff0
cmpl $0x0, -0x78(%rbp)
jne 0x11002
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x11170
movq -0x88(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x48, %edx
callq 0xf780
movb %al, -0x79(%rbp)
cmpb $0x0, -0x79(%rbp)
je 0x11065
jmp 0x11022
leaq 0x15270(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11057
movq 0x14fa3(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movzbl -0x79(%rbp), %r8d
leaq 0xcf58(%rip), %rsi      # 0x1df9c
leaq 0xbc5f(%rip), %rdx      # 0x1ccaa
movl $0x46, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11059
movl $0xfffffffe, -0xc(%rbp) # imm = 0xFFFFFFFE
jmp 0x11170
movq -0x88(%rbp), %rax
movl -0x67(%rbp), %ecx
movl %ecx, 0x1c(%rax)
movb $0x0, 0x20(%rax)
leaq 0x1521c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x110b1
movq -0x88(%rbp), %r8
movq 0x14f28(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
addq $0x1c, %r8
leaq 0xbdd1(%rip), %rsi      # 0x1ce6f
leaq 0xbc05(%rip), %rdx      # 0x1ccaa
movl $0x4c, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x110b3
movq -0x88(%rbp), %rax
movzbl -0x5b(%rbp), %ecx
andl $0xf, %ecx
movl %ecx, 0x18(%rax)
leaq 0x151ce(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x110ff
movq -0x88(%rbp), %rax
movq 0x14eda(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x18(%rax), %r8d
leaq 0xbd9c(%rip), %rsi      # 0x1ce88
leaq 0xbbb7(%rip), %rdx      # 0x1ccaa
movl $0x4e, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11101
movq -0x88(%rbp), %rax
movzbl -0x5e(%rbp), %ecx
movl %ecx, 0x10(%rax)
movzbl -0x5d(%rbp), %ecx
shll $0x10, %ecx
movzbl -0x5c(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
movzbl -0x71(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
leaq 0x1516a(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11167
movq -0x88(%rbp), %rax
movq 0x14e76(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
leaq 0xbd52(%rip), %rsi      # 0x1cea6
leaq 0xbb4f(%rip), %rdx      # 0x1ccaa
movl $0x55, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11169
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xa8, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)