FreeBSD/usr.sbin/bluetooth/hccontrol/host_controller_baseband.c
/* Send Write_Stored_Link_Key command to the unit */
Send Write_Stored_Link_Key command to the unit
Send Write_Stored_Link_Key command to the unit
static int
hci_write_stored_link_key(int s, int argc, char **argv)
{
	struct {
		ng_hci_write_stored_link_key_cp	p;
		bdaddr_t			bdaddr;
		uint8_t				key[NG_HCI_KEY_SIZE];
	}					cp;
	ng_hci_write_stored_link_key_rp		rp;
	int32_t					n;
	memset(&cp, 0, sizeof(cp));
	switch (argc) {
	case 2:
		cp.p.num_keys_write = 1;
		if (!bt_aton(argv[0], &cp.bdaddr)) {
			struct hostent	*he = NULL;
			if ((he = bt_gethostbyname(argv[0])) == NULL)
				return (USAGE);
			memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr));
		}
		if (hci_hexstring2array(argv[1], cp.key, sizeof(cp.key)) < 0)
			return (USAGE);
		break;
	default:
		return (USAGE);
	}
	n = sizeof(rp);
	if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, 
			NG_HCI_OCF_WRITE_STORED_LINK_KEY),
			(char const *) &cp, sizeof(cp),
			(char *) &rp, &n) == ERROR)
		return (ERROR);
	if (rp.status != 0x00) {
		fprintf(stdout, "Status: %s [%#02x]\n", 
			hci_status2str(rp.status), rp.status);
		return (FAILED);
	}
	fprintf(stdout, "Number of keys written: %d\n", rp.num_keys_written);
	return (OK);
}
static int hci_write_stored_link_key ( int s , int argc , char * * argv ) { struct { ng_hci_write_stored_link_key_cp p ; bdaddr_t bdaddr ; uint8_t key [ NG_HCI_KEY_SIZE ] ; } cp ; ng_hci_write_stored_link_key_rp rp ; int32_t n ; memset ( & cp , 0 , sizeof ( cp ) ) ; switch ( argc ) { case 2 : cp . p . num_keys_write = 1 ; if ( ! bt_aton ( argv [ 0 ] , & cp . bdaddr ) ) { struct hostent * he = NULL ; if ( ( he = bt_gethostbyname ( argv [ 0 ] ) ) == NULL ) return ( USAGE ) ; memcpy ( & cp . bdaddr , he -> h_addr , sizeof ( cp . bdaddr ) ) ; } if ( hci_hexstring2array ( argv [ 1 ] , cp . key , sizeof ( cp . key ) ) < 0 ) return ( USAGE ) ; break ; default : return ( USAGE ) ; } n = sizeof ( rp ) ; if ( hci_request ( s , NG_HCI_OPCODE ( NG_HCI_OGF_HC_BASEBAND , NG_HCI_OCF_WRITE_STORED_LINK_KEY ) , ( char const * ) & cp , sizeof ( cp ) , ( char * ) & rp , & n ) == ERROR ) return ( ERROR ) ; if ( rp . status != 0x00 ) { fprintf ( stdout , " \n " , hci_status2str ( rp . status ) , rp . status ) ; return ( FAILED ) ; } fprintf ( stdout , " \n " , rp . num_keys_written ) ; return ( OK ) ; }
Send Write_Stored_Link_Key command to the unit
Send Write_Stored_Link_Key command to the unit
/* parse BD_ADDR */ /* parse key */ /* send command */