// File: /workspace/github_c_makefile_star2_O0/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_vendor_change_speed_h5
int rtk_vendor_change_speed_h5(int fd, RT_U32 baudrate)
{
	struct sk_buff *cmd_change_bdrate = NULL;
	unsigned char cmd[7] = { 0 };
	int retlen;
	unsigned char bytes[READ_DATA_SIZE];
	struct sigaction sa;

	sa.sa_handler = h5_tinit_sig_alarm;
	sigaction(SIGALRM, &sa, NULL);

	cmd[0] = 0x17;	//ocf
	cmd[1] = 0xfc;	//ogf, vendor specified

	cmd[2] = 4;	//length;

	baudrate = cpu_to_le32(baudrate);
#ifdef BAUDRATE_4BYTES
	memcpy((RT_U16 *) & cmd[3], &baudrate, 4);
#else
	memcpy((RT_U16 *) & cmd[3], &baudrate, 2);

	cmd[5] = 0;
	cmd[6] = 0;
#endif

	RS_DBG("baudrate in change speed command: 0x%x 0x%x 0x%x 0x%x \n",
	       cmd[3], cmd[4], cmd[5], cmd[6]);

	cmd_change_bdrate =
	    h5_prepare_pkt(&rtk_hw_cfg, cmd, 7, HCI_COMMAND_PKT);
	if (!cmd_change_bdrate) {
		RS_ERR("Prepare command packet for change speed fail");
		return -1;
	}

	rtk_hw_cfg.host_last_cmd = cmd_change_bdrate;
	alarm(1);
	write(fd, cmd_change_bdrate->data, cmd_change_bdrate->data_len);

	while (rtk_hw_cfg.link_estab_state == H5_INIT) {
		if ((retlen = read_check_rtk(fd, &bytes, READ_DATA_SIZE)) == -1) {
			perror("read fail");
			return -1;
		}
		//add pure ack check
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}

	alarm(0);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
leaq -0x1f(%rbp), %rdi
xorl %esi, %esi
movl $0x7, %edx
callq 0x20d0
leaq 0x160(%rip), %rax       # 0x54f0
movq %rax, -0xd8(%rbp)
movl $0xe, %edi
leaq -0xd8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
movb $0x17, -0x1f(%rbp)
movb $-0x4, -0x1e(%rbp)
movb $0x4, -0x1d(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpb $0x0, 0xaf05(%rip)      # 0x102d0
je 0x5401
movq 0xac24(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movzbl -0x1c(%rbp), %ecx
movzbl -0x1b(%rbp), %r8d
movzbl -0x1a(%rbp), %r9d
movzbl -0x19(%rbp), %eax
leaq 0x6735(%rip), %rsi      # 0xbb25
leaq 0x6192(%rip), %rdx      # 0xb589
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2150
jmp 0x5403
leaq -0x1f(%rbp), %rsi
leaq 0xb2c2(%rip), %rdi      # 0x106d0
movl $0x7, %edx
movl $0x1, %ecx
callq 0x5600
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5455
jmp 0x542a
movq 0xabc7(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x6727(%rip), %rsi      # 0xbb62
leaq 0x6147(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x54dd
movq -0x18(%rbp), %rax
movq %rax, 0xb290(%rip)      # 0x106f0
movl $0x1, %edi
callq 0x20f0
movl -0x8(%rbp), %edi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
callq 0x2070
cmpl $0x2, 0xb25a(%rip)      # 0x106e4
jne 0x54cf
movl -0x8(%rbp), %edi
leaq -0x40(%rbp), %rsi
movl $0x10, %edx
callq 0x5850
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x54ba
leaq 0x6855(%rip), %rdi      # 0xbd01
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x54dd
movl -0x24(%rbp), %edx
leaq 0xb20c(%rip), %rdi      # 0x106d0
leaq -0x40(%rbp), %rsi
callq 0x58f0
jmp 0x5483
xorl %edi, %edi
callq 0x20f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)