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