/*-
* Copyright (c) 2007 Iain Hibbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2007 Iain Hibbert. All rights reserved.");
__RCSID("$NetBSD: btkey.c,v 1.5 2021/08/25 22:52:25 rillig Exp $");
fprintf(stderr,
"Where:\n"
"\t-a address remote device address\n"
"\t-c clear from file\n"
"\t-C clear from device\n"
"\t-d device local device address\n"
"\t-k key user specified link_key\n"
"\t-l list file keys\n"
"\t-L list device keys\n"
"\t-r read from file\n"
"\t-R read from device\n"
"\t-w write to file\n"
"\t-W write to device\n"
"\n");
exit(EXIT_FAILURE);
}
static bool
scan_key(const char *arg)
{
static const char digits[] = "0123456789abcdef";
const char *p;
int i, j;
memset(key, 0, sizeof(key));
for (i = 0 ; i < HCI_KEY_SIZE ; i++) {
for (j = 0 ; j < 2 ; j++) {
if (*arg == '\0')
return true;
for (p = digits ;
*p != tolower((unsigned char)*arg) ;
p++)
if (*p == '\0')
return false;
arg++;
key[i] = (key[i] << 4) + (p - digits);
}
}
if (*arg != '\0')
return false;
return true;
}
void
print_key(const char *type, const uint8_t *src)
{
int i;
printf("%10s: ", type);
for (i = 0 ; i < HCI_KEY_SIZE ; i++)
printf("%2.2x", src[i]);