xref: /dragonfly/usr.sbin/bthcid/bthcid.h (revision c1543a89)
1 /* $NetBSD: bthcid.h,v 1.3 2006/09/26 19:18:19 plunky Exp $ */
2 /* $DragonFly: src/usr.sbin/bthcid/bthcid.h,v 1.1 2008/01/30 14:10:19 hasso Exp $ */
3 
4 /*-
5  * Copyright (c) 2006 Itronix Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of Itronix Inc. may not be used to endorse
17  *    or promote products derived from this software without specific
18  *    prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _BTHCID_H_
34 #define _BTHCID_H_	1
35 
36 #include <sys/queue.h>
37 
38 /* config.c */
39 uint8_t		*lookup_key		(bdaddr_t *, bdaddr_t *);
40 void		 save_key		(bdaddr_t *, bdaddr_t *, uint8_t *);
41 void 		 create_dict(bdaddr_t *laddr, bdaddr_t *raddr, uint8_t * key);
42 
43 /* client.c */
44 int		 init_control		(const char *, mode_t);
45 int		 send_client_request	(bdaddr_t *, bdaddr_t *, int);
46 uint8_t		*lookup_pin		(bdaddr_t *, bdaddr_t *);
47 uint8_t		*lookup_pin_conf	(bdaddr_t *, bdaddr_t *);
48 
49 /* hci.c */
50 int		 init_hci		(bdaddr_t *);
51 int		 send_pin_code_reply	(int, struct sockaddr_bt *, bdaddr_t *, uint8_t *);
52 
53 #define BTHCID_BUFFER_SIZE	512
54 #define BTHCID_IDENT		"bthcid"
55 #define BTHCID_PIDFILE		"/var/run/" BTHCID_IDENT ".pid"
56 #define BTHCID_KEYSFILE		"/var/db/"  BTHCID_IDENT ".keys"
57 
58 struct link_key
59 {
60 	bdaddr_t		 bdaddr; /* remote device BDADDR */
61 	char			*name;   /* remote device name */
62 	uint8_t			*key;    /* link key (or NULL if no key) */
63 	char			*pin;    /* pin (or NULL if no pin) */
64 	LIST_ENTRY(link_key)	 next;   /* link to the next */
65 };
66 typedef struct link_key		link_key_t;
67 typedef struct link_key *	link_key_p;
68 
69 extern const char		*config_file;
70 
71 #if __config_debug__
72 void		dump_config	(void);
73 #endif
74 
75 #ifndef bdaddr_p
76 #define bdaddr_p bdaddr_t *
77 #endif
78 
79 void		read_config_file(void);
80 void		clean_config	(void);
81 link_key_p	get_key		(bdaddr_p bdaddr, int exact_match);
82 
83 int		read_keys_file  (void);
84 int		dump_keys_file  (void);
85 
86 #endif	/* _BTHCID_H_ */
87