Lines Matching +full:key +full:-
2 /*-
5 * SPDX-License-Identifier: BSD-2-Clause
7 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
51 static void free_key (link_key_p key);
59 static link_key_p key = NULL; variable
77 key = (link_key_p) malloc(sizeof(*key));
78 if (key == NULL) {
84 memset(key, 0, sizeof(*key));
88 if (get_key(&key->bdaddr, 1) != NULL) {
91 bt_ntoa(&key->bdaddr, NULL));
92 free_key(key);
94 LIST_INSERT_HEAD(&link_keys, key, next);
96 key = NULL;
106 | key
112 if (!bt_aton($2, &key->bdaddr)) {
122 if (key->name != NULL)
123 free(key->name);
125 key->name = strdup($2);
126 if (key->name == NULL) {
134 key: T_KEY T_HEXSTRING
138 if (key->key != NULL)
139 free(key->key);
141 key->key = (uint8_t *) malloc(NG_HCI_KEY_SIZE);
142 if (key->key == NULL) {
144 "link key");
148 memset(key->key, 0, NG_HCI_KEY_SIZE);
155 key->key[i] = hexa2int8((char *)($2) + 2*i);
159 if (key->key != NULL)
160 free(key->key);
162 key->key = NULL;
168 if (key->pin != NULL)
169 free(key->pin);
171 key->pin = strdup($2);
172 if (key->pin == NULL) {
180 if (key->pin != NULL)
181 free(key->pin);
183 key->pin = NULL;
196 /* Re-read config file */
231 link_key_p key = NULL; in clean_config() local
233 while ((key = LIST_FIRST(&link_keys)) != NULL) { in clean_config()
234 LIST_REMOVE(key, next); in clean_config()
235 free_key(key); in clean_config()
239 /* Find link key entry in the list. Return exact or default match */
243 link_key_p key = NULL, defkey = NULL; in get_key() local
245 LIST_FOREACH(key, &link_keys, next) { in get_key()
246 if (memcmp(bdaddr, &key->bdaddr, sizeof(key->bdaddr)) == 0) in get_key()
250 if (memcmp(NG_HCI_BDADDR_ANY, &key->bdaddr, in get_key()
251 sizeof(key->bdaddr)) == 0) in get_key()
252 defkey = key; in get_key()
255 return ((key != NULL)? key : defkey); in get_key()
263 link_key_p key = NULL; in dump_config() local
266 LIST_FOREACH(key, &link_keys, next) { in dump_config()
267 if (key->key != NULL) in dump_config()
270 key->key[0], key->key[1], key->key[2], in dump_config()
271 key->key[3], key->key[4], key->key[5], in dump_config()
272 key->key[6], key->key[7], key->key[8], in dump_config()
273 key->key[9], key->key[10], key->key[11], in dump_config()
274 key->key[12], key->key[13], key->key[14], in dump_config()
275 key->key[15]); in dump_config()
281 "key %s", in dump_config()
282 (key->name != NULL)? key->name : "noname", in dump_config()
283 bt_ntoa(&key->bdaddr, NULL), in dump_config()
284 (key->pin != NULL)? key->pin : "nopin", in dump_config()
285 (key->key != NULL)? buffer : "nokey"); in dump_config()
295 link_key_t *key = NULL; in read_keys_file() local
307 return (-1); in read_keys_file()
321 if ((key = get_key(&bdaddr, 1)) == NULL) in read_keys_file()
324 if (key->key == NULL) { in read_keys_file()
325 key->key = (uint8_t *) malloc(NG_HCI_KEY_SIZE); in read_keys_file()
326 if (key->key == NULL) { in read_keys_file()
327 syslog(LOG_ERR, "Could not allocate link key"); in read_keys_file()
332 memset(key->key, 0, NG_HCI_KEY_SIZE); in read_keys_file()
339 key->key[i] = hexa2int8(cp + 2*i); in read_keys_file()
341 syslog(LOG_DEBUG, "Restored link key for the entry, " \ in read_keys_file()
343 bt_ntoa(&key->bdaddr, NULL), in read_keys_file()
344 (key->name != NULL)? key->name : "No name"); in read_keys_file()
356 link_key_p key = NULL; in dump_keys_file() local
364 return (-1); in dump_keys_file()
367 LIST_FOREACH(key, &link_keys, next) { in dump_keys_file()
368 if (key->key == NULL) in dump_keys_file()
373 bt_ntoa(&key->bdaddr, NULL), in dump_keys_file()
374 key->key[0], key->key[1], key->key[2], key->key[3], in dump_keys_file()
375 key->key[4], key->key[5], key->key[6], key->key[7], in dump_keys_file()
376 key->key[8], key->key[9], key->key[10], key->key[11], in dump_keys_file()
377 key->key[12], key->key[13], key->key[14], key->key[15]); in dump_keys_file()
392 return (-1); in dump_keys_file()
398 /* Free key entry */
400 free_key(link_key_p key) in free_key() argument
402 if (key->name != NULL) in free_key()
403 free(key->name); in free_key()
404 if (key->key != NULL) in free_key()
405 free(key->key); in free_key()
406 if (key->pin != NULL) in free_key()
407 free(key->pin); in free_key()
409 memset(key, 0, sizeof(*key)); in free_key()
410 free(key); in free_key()
418 return (*a - '0'); in hexa2int4()
421 return (*a - 'A' + 0xa); in hexa2int4()
424 return (*a - 'a' + 0xa); in hexa2int4()