1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/* $NetBSD: sdpd.h,v 1.2 2012/03/01 22:38:31 joerg Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
* 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 Itronix Inc. may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``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 ITRONIX INC. 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.
*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*/
#ifndef _SDPD_H_
#define _SDPD_H_
#include <sys/types.h>
#include <sys/queue.h>
#include <bluetooth.h>
#include <sdp.h>
#include <stdbool.h>
/*
* Service Record entry
*/
struct record {
int fd; /* owner */
bool valid; /* record is current */
uint32_t handle; /* ServiceRecord handle */
sdp_data_t data; /* ServiceRecord data */
bdaddr_t bdaddr; /* restricted device address */
int refcnt; /* reference count */
fd_set refset; /* reference bitset */
LIST_ENTRY(record) next; /* next ServiceRecord */
uint8_t ext[0]; /* raw data storage ... */
};
typedef struct record record_t;
/*
* File descriptor (client) index entry
*/
struct fd_idx {
bool valid; /* descriptor is valid */
bool server; /* descriptor is listening */
bool control;/* descriptor is control socket */
bool priv; /* descriptor may modify service record db */
uint16_t omtu; /* outgoing MTU */
uint16_t offset; /* stored ContinuationState */
bdaddr_t bdaddr; /* clients local device address */
};
typedef struct fd_idx fd_idx_t;
/*
* SDP server
*/
struct server {
uint16_t imtu; /* incoming MTU */
uint8_t * ibuf; /* input buffer */
size_t ctllen; /* control msg buffer length */
uint8_t * ctlbuf; /* control msg buffer */
sdp_pdu_t pdu; /* PDU header */
uint16_t omtu; /* outgoing MTU */
uint8_t * obuf; /* output buffer */
uint32_t handle; /* next ServiceRecordHandle */
LIST_HEAD(, record) rlist; /* ServiceRecord list */
int fdmax; /* descriptor max index */
fd_idx_t * fdidx; /* descriptor index */
fd_set fdset; /* current descriptor set */
const char * sgroup; /* privileged group */
};
typedef struct server server_t;
/* compat.c */
uint16_t compat_register_request(server_t *, int);
uint16_t compat_change_request(server_t *, int);
/* db.c */
bool db_init(server_t *);
bool db_next(server_t *, int, record_t **);
void db_select_ssp(server_t *, int, sdp_data_t *);
void db_select_handle(server_t *, int, uint32_t);
bool db_create(server_t *, int, const bdaddr_t *, uint32_t, sdp_data_t *);
void db_unselect(server_t *, int);
void db_release(server_t *, int);
/* log.c */
void log_open(char const *, bool);
void log_close(void);
void log_emerg(char const *, ...) __printflike(1, 2);
void log_alert(char const *, ...) __printflike(1, 2);
void log_crit(char const *, ...) __printflike(1, 2);
void log_err(char const *, ...) __printflike(1, 2);
void log_warning(char const *, ...) __printflike(1, 2);
void log_notice(char const *, ...) __printflike(1, 2);
void log_info(char const *, ...) __printflike(1, 2);
void log_debug(char const *, ...) __printflike(1, 2);
/* record.c */
uint16_t record_insert_request(server_t *, int);
uint16_t record_update_request(server_t *, int);
uint16_t record_remove_request(server_t *, int);
/* server.c */
bool server_init(server_t *, const char *, const char *);
void server_shutdown(server_t *);
bool server_do(server_t *);
void server_error_response(server_t *, int, uint16_t);
/* service.c */
uint16_t service_search_request(server_t *, int);
uint16_t service_attribute_request(server_t *, int);
uint16_t service_search_attribute_request(server_t *, int);
#endif /* _SDPD_H_ */
|