xref: /freebsd/usr.sbin/bluetooth/sdpd/server.h (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1 /*-
2  * server.h
3  *
4  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5  *
6  * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $Id: server.h,v 1.5 2004/01/13 01:54:39 max Exp $
31  * $FreeBSD$
32  */
33 
34 #ifndef _SERVER_H_
35 #define _SERVER_H_
36 
37 /*
38  * File descriptor index entry
39  */
40 
41 struct fd_idx
42 {
43 	unsigned	 valid    : 1;	/* descriptor is valid */
44 	unsigned	 server   : 1;	/* descriptor is listening */
45 	unsigned	 control  : 1;	/* descriptor is a control socket */
46 	unsigned	 priv     : 1;	/* descriptor is privileged */
47 	unsigned	 reserved : 1;
48 	unsigned	 rsp_cs   : 11; /* response continuation state */
49 	uint16_t	 rsp_size;	/* response size */
50 	uint16_t	 rsp_limit;	/* response limit */
51 	uint16_t	 omtu;		/* outgoing MTU */
52 	uint8_t		*rsp;		/* outgoing buffer */
53 };
54 
55 typedef struct fd_idx	fd_idx_t;
56 typedef struct fd_idx *	fd_idx_p;
57 
58 /*
59  * SDP server
60  */
61 
62 struct server
63 {
64 	uint32_t		 imtu;		/* incoming MTU */
65 	uint8_t			*req;		/* incoming buffer */
66 	int32_t			 maxfd;		/* max. descriptor is the set */
67 	fd_set			 fdset;		/* current descriptor set */
68 	fd_idx_p		 fdidx;		/* descriptor index */
69 	struct sockaddr_l2cap	 req_sa;	/* local address */
70 };
71 
72 typedef struct server	server_t;
73 typedef struct server *	server_p;
74 
75 /*
76  * External API
77  */
78 
79 int32_t	server_init(server_p srv, const char *control);
80 void	server_shutdown(server_p srv);
81 int32_t	server_do(server_p srv);
82 
83 int32_t	server_prepare_service_search_response(server_p srv, int32_t fd);
84 int32_t	server_send_service_search_response(server_p srv, int32_t fd);
85 
86 int32_t	server_prepare_service_attribute_response(server_p srv, int32_t fd);
87 int32_t	server_send_service_attribute_response(server_p srv, int32_t fd);
88 
89 int32_t	server_prepare_service_search_attribute_response(server_p srv, int32_t fd);
90 #define	server_send_service_search_attribute_response \
91 	server_send_service_attribute_response
92 
93 int32_t	server_prepare_service_register_response(server_p srv, int32_t fd);
94 int32_t	server_send_service_register_response(server_p srv, int32_t fd);
95 
96 int32_t	server_prepare_service_unregister_response(server_p srv, int32_t fd);
97 #define	server_send_service_unregister_response \
98 	server_send_service_register_response
99 
100 int32_t	server_prepare_service_change_response(server_p srv, int32_t fd);
101 #define	server_send_service_change_response \
102 	server_send_service_register_response
103 
104 #endif /* ndef _SERVER_H_ */
105