xref: /netbsd/usr.sbin/sdpd/sdpd.h (revision f8e83280)
1 /*	$NetBSD: sdpd.h,v 1.2 2012/03/01 22:38:31 joerg Exp $	*/
2 
3 /*-
4  * Copyright (c) 2006 Itronix Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of Itronix Inc. may not be used to endorse
16  *    or promote products derived from this software without specific
17  *    prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*
32  * Copyright (c) 2009 The NetBSD Foundation, Inc.
33  * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  */
57 
58 #ifndef _SDPD_H_
59 #define _SDPD_H_
60 
61 #include <sys/types.h>
62 #include <sys/queue.h>
63 
64 #include <bluetooth.h>
65 #include <sdp.h>
66 #include <stdbool.h>
67 
68 /*
69  * Service Record entry
70  */
71 struct record {
72 	int			fd;	/* owner */
73 	bool			valid;	/* record is current */
74 	uint32_t		handle;	/* ServiceRecord handle */
75 	sdp_data_t		data;	/* ServiceRecord data */
76 	bdaddr_t		bdaddr;	/* restricted device address */
77 	int			refcnt;	/* reference count */
78 	fd_set			refset;	/* reference bitset */
79 	LIST_ENTRY(record)	next;	/* next ServiceRecord */
80 	uint8_t			ext[0];	/* raw data storage ... */
81 };
82 
83 typedef	struct record record_t;
84 
85 /*
86  * File descriptor (client) index entry
87  */
88 struct fd_idx {
89 	bool			valid;	/* descriptor is valid */
90 	bool			server;	/* descriptor is listening */
91 	bool			control;/* descriptor is control socket */
92 	bool			priv;	/* descriptor may modify service record db */
93 	uint16_t		omtu;	/* outgoing MTU */
94 	uint16_t		offset;	/* stored ContinuationState */
95 	bdaddr_t		bdaddr;	/* clients local device address */
96 };
97 
98 typedef struct fd_idx fd_idx_t;
99 
100 /*
101  * SDP server
102  */
103 struct server {
104 	uint16_t		imtu;	/* incoming MTU */
105 	uint8_t *		ibuf;	/* input buffer */
106 	size_t			ctllen;	/* control msg buffer length */
107 	uint8_t *		ctlbuf;	/* control msg buffer */
108 	sdp_pdu_t		pdu;	/* PDU header */
109 	uint16_t		omtu;	/* outgoing MTU */
110 	uint8_t *		obuf;	/* output buffer */
111 	uint32_t		handle;	/* next ServiceRecordHandle */
112 	LIST_HEAD(, record)	rlist;	/* ServiceRecord list */
113 	int			fdmax;	/* descriptor max index */
114 	fd_idx_t *		fdidx;	/* descriptor index */
115 	fd_set			fdset;	/* current descriptor set */
116 	const char *		sgroup;	/* privileged group */
117 };
118 
119 typedef struct server server_t;
120 
121 /* compat.c */
122 uint16_t compat_register_request(server_t *, int);
123 uint16_t compat_change_request(server_t *, int);
124 
125 /* db.c */
126 bool	db_init(server_t *);
127 bool	db_next(server_t *, int, record_t **);
128 void	db_select_ssp(server_t *, int, sdp_data_t *);
129 void	db_select_handle(server_t *, int, uint32_t);
130 bool	db_create(server_t *, int, const bdaddr_t *, uint32_t, sdp_data_t *);
131 void	db_unselect(server_t *, int);
132 void	db_release(server_t *, int);
133 
134 /* log.c */
135 void	log_open(char const *, bool);
136 void	log_close(void);
137 void	log_emerg(char const *, ...) __printflike(1, 2);
138 void	log_alert(char const *, ...) __printflike(1, 2);
139 void	log_crit(char const *, ...) __printflike(1, 2);
140 void	log_err(char const *, ...) __printflike(1, 2);
141 void	log_warning(char const *, ...) __printflike(1, 2);
142 void	log_notice(char const *, ...) __printflike(1, 2);
143 void	log_info(char const *, ...) __printflike(1, 2);
144 void	log_debug(char const *, ...) __printflike(1, 2);
145 
146 /* record.c */
147 uint16_t record_insert_request(server_t *, int);
148 uint16_t record_update_request(server_t *, int);
149 uint16_t record_remove_request(server_t *, int);
150 
151 /* server.c */
152 bool	server_init(server_t *, const char *, const char *);
153 void	server_shutdown(server_t *);
154 bool	server_do(server_t *);
155 void	server_error_response(server_t *, int, uint16_t);
156 
157 /* service.c */
158 uint16_t service_search_request(server_t *, int);
159 uint16_t service_attribute_request(server_t *, int);
160 uint16_t service_search_attribute_request(server_t *, int);
161 
162 #endif /* _SDPD_H_ */
163