Home | History | Annotate | Line # | Download | only in netbt
bluetooth.h revision 1.1
      1  1.1  gdamore /*	$NetBSD: bluetooth.h,v 1.1 2006/06/19 15:44:45 gdamore Exp $	*/
      2  1.1  gdamore 
      3  1.1  gdamore /*-
      4  1.1  gdamore  * Copyright (c) 2005 Iain Hibbert.
      5  1.1  gdamore  * Copyright (c) 2006 Itronix Inc.
      6  1.1  gdamore  * All rights reserved.
      7  1.1  gdamore  *
      8  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
      9  1.1  gdamore  * modification, are permitted provided that the following conditions
     10  1.1  gdamore  * are met:
     11  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     12  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     13  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     16  1.1  gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     17  1.1  gdamore  *    or promote products derived from this software without specific
     18  1.1  gdamore  *    prior written permission.
     19  1.1  gdamore  *
     20  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     21  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     24  1.1  gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25  1.1  gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26  1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27  1.1  gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  gdamore  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  gdamore  */
     32  1.1  gdamore 
     33  1.1  gdamore #ifndef _NETBT_BLUETOOTH_H_
     34  1.1  gdamore #define _NETBT_BLUETOOTH_H_
     35  1.1  gdamore 
     36  1.1  gdamore #include <sys/socket.h>
     37  1.1  gdamore 
     38  1.1  gdamore /*
     39  1.1  gdamore  * Bluetooth Address Family Protocol Numbers
     40  1.1  gdamore  */
     41  1.1  gdamore #define BTPROTO_HCI	1
     42  1.1  gdamore #define BTPROTO_L2CAP	2
     43  1.1  gdamore #define BTPROTO_RFCOMM	3
     44  1.1  gdamore #define BTPROTO_SCO	4
     45  1.1  gdamore 
     46  1.1  gdamore /* All sizes are in bytes */
     47  1.1  gdamore #define BLUETOOTH_BDADDR_SIZE	6
     48  1.1  gdamore 
     49  1.1  gdamore /*
     50  1.1  gdamore  * Bluetooth device address
     51  1.1  gdamore  */
     52  1.1  gdamore typedef struct {
     53  1.1  gdamore 	uint8_t	b[BLUETOOTH_BDADDR_SIZE];
     54  1.1  gdamore } __attribute__ ((packed)) bdaddr_t;
     55  1.1  gdamore 
     56  1.1  gdamore /*
     57  1.1  gdamore  * bdaddr utility functions
     58  1.1  gdamore  */
     59  1.1  gdamore static __inline int __unused
     60  1.1  gdamore bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
     61  1.1  gdamore {
     62  1.1  gdamore 
     63  1.1  gdamore 	return (a->b[0] == b->b[0] && a->b[1] == b->b[1]
     64  1.1  gdamore 		&& a->b[2] == b->b[2] && a->b[3] == b->b[3]
     65  1.1  gdamore 		&& a->b[4] == b->b[4] && a->b[5] == b->b[5]);
     66  1.1  gdamore }
     67  1.1  gdamore 
     68  1.1  gdamore static __inline int __unused
     69  1.1  gdamore bdaddr_any(const bdaddr_t *a)
     70  1.1  gdamore {
     71  1.1  gdamore 
     72  1.1  gdamore 	return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0
     73  1.1  gdamore 		&& a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
     74  1.1  gdamore }
     75  1.1  gdamore 
     76  1.1  gdamore static __inline void __unused
     77  1.1  gdamore bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
     78  1.1  gdamore {
     79  1.1  gdamore 
     80  1.1  gdamore 	d->b[0] = s->b[0];
     81  1.1  gdamore 	d->b[1] = s->b[1];
     82  1.1  gdamore 	d->b[2] = s->b[2];
     83  1.1  gdamore 	d->b[3] = s->b[3];
     84  1.1  gdamore 	d->b[4] = s->b[4];
     85  1.1  gdamore 	d->b[5] = s->b[5];
     86  1.1  gdamore }
     87  1.1  gdamore 
     88  1.1  gdamore /*
     89  1.1  gdamore  * Socket address used by Bluetooth protocols
     90  1.1  gdamore  */
     91  1.1  gdamore struct sockaddr_bt {
     92  1.1  gdamore 	uint8_t		bt_len;
     93  1.1  gdamore 	sa_family_t	bt_family;
     94  1.1  gdamore 	bdaddr_t	bt_bdaddr;
     95  1.1  gdamore 	uint16_t	bt_psm;
     96  1.1  gdamore 	uint8_t		bt_channel;
     97  1.1  gdamore 	uint8_t		bt_zero[5];
     98  1.1  gdamore };
     99  1.1  gdamore 
    100  1.1  gdamore /* Note: this is actually 6 bytes including terminator */
    101  1.1  gdamore #define BDADDR_ANY	((const bdaddr_t *) "\000\000\000\000\000")
    102  1.1  gdamore 
    103  1.1  gdamore #ifdef _KERNEL
    104  1.1  gdamore 
    105  1.1  gdamore MALLOC_DECLARE(M_BLUETOOTH);
    106  1.1  gdamore 
    107  1.1  gdamore /*
    108  1.1  gdamore  * Bluetooth Protocol API callback methods
    109  1.1  gdamore  */
    110  1.1  gdamore struct mbuf;
    111  1.1  gdamore struct btproto {
    112  1.1  gdamore 	void (*connecting)(void *);
    113  1.1  gdamore 	void (*connected)(void *);
    114  1.1  gdamore 	void (*disconnected)(void *, int);
    115  1.1  gdamore 	void *(*newconn)(void *, struct sockaddr_bt *, struct sockaddr_bt *);
    116  1.1  gdamore 	void (*complete)(void *, int);
    117  1.1  gdamore 	void (*input)(void *, struct mbuf *);
    118  1.1  gdamore };
    119  1.1  gdamore 
    120  1.1  gdamore /*
    121  1.1  gdamore  * Debugging stuff
    122  1.1  gdamore  */
    123  1.1  gdamore #ifndef BLUETOOTH
    124  1.1  gdamore #include "opt_bluetooth.h"
    125  1.1  gdamore #endif
    126  1.1  gdamore 
    127  1.1  gdamore #ifdef BLUETOOTH_DEBUG
    128  1.1  gdamore extern int bluetooth_debug;
    129  1.1  gdamore # define DPRINTF(fmt, args...)	do {			\
    130  1.1  gdamore 	if (bluetooth_debug)				\
    131  1.1  gdamore 		printf("%s: "fmt, __func__ , ##args);	\
    132  1.1  gdamore } while (/* CONSTCOND */0)
    133  1.1  gdamore 
    134  1.1  gdamore # define DPRINTFN(n, fmt, args...)	do {		\
    135  1.1  gdamore 	if (bluetooth_debug > (n))			\
    136  1.1  gdamore 		printf("%s: "fmt, __func__ , ##args);	\
    137  1.1  gdamore } while (/* CONSTCOND */0)
    138  1.1  gdamore 
    139  1.1  gdamore # define UNKNOWN(value)			\
    140  1.1  gdamore 		printf("%s: %s = %d unknown!\n", __func__, #value, (value));
    141  1.1  gdamore #else
    142  1.1  gdamore # define DPRINTF(...)
    143  1.1  gdamore # define DPRINTFN(...)
    144  1.1  gdamore # define UNKNOWN(x)
    145  1.1  gdamore #endif	/* BLUETOOTH_DEBUG */
    146  1.1  gdamore 
    147  1.1  gdamore #endif	/* _KERNEL */
    148  1.1  gdamore 
    149  1.1  gdamore #endif	/* _NETBT_BLUETOOTH_H_ */
    150