Home | History | Annotate | Line # | Download | only in netbt
      1  1.12     rmind /*	$NetBSD: bluetooth.h,v 1.12 2014/05/18 14:46:16 rmind 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.3    plunky #include <sys/types.h>
     38   1.1   gdamore 
     39   1.1   gdamore /*
     40   1.1   gdamore  * Bluetooth Address Family Protocol Numbers
     41   1.1   gdamore  */
     42   1.1   gdamore #define BTPROTO_HCI	1
     43   1.1   gdamore #define BTPROTO_L2CAP	2
     44   1.1   gdamore #define BTPROTO_RFCOMM	3
     45   1.1   gdamore #define BTPROTO_SCO	4
     46   1.1   gdamore 
     47   1.1   gdamore /* All sizes are in bytes */
     48   1.1   gdamore #define BLUETOOTH_BDADDR_SIZE	6
     49   1.1   gdamore 
     50   1.1   gdamore /*
     51   1.1   gdamore  * Bluetooth device address
     52   1.1   gdamore  */
     53   1.1   gdamore typedef struct {
     54   1.1   gdamore 	uint8_t	b[BLUETOOTH_BDADDR_SIZE];
     55   1.8  gmcgarry } __packed bdaddr_t;
     56   1.1   gdamore 
     57   1.1   gdamore /*
     58   1.1   gdamore  * bdaddr utility functions
     59   1.1   gdamore  */
     60   1.4  christos static __inline int
     61   1.1   gdamore bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
     62   1.1   gdamore {
     63   1.1   gdamore 
     64   1.1   gdamore 	return (a->b[0] == b->b[0] && a->b[1] == b->b[1]
     65   1.1   gdamore 		&& a->b[2] == b->b[2] && a->b[3] == b->b[3]
     66   1.1   gdamore 		&& a->b[4] == b->b[4] && a->b[5] == b->b[5]);
     67   1.1   gdamore }
     68   1.1   gdamore 
     69   1.4  christos static __inline int
     70   1.1   gdamore bdaddr_any(const bdaddr_t *a)
     71   1.1   gdamore {
     72   1.1   gdamore 
     73   1.1   gdamore 	return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0
     74   1.1   gdamore 		&& a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
     75   1.1   gdamore }
     76   1.1   gdamore 
     77   1.4  christos static __inline void
     78   1.1   gdamore bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
     79   1.1   gdamore {
     80   1.1   gdamore 
     81   1.1   gdamore 	d->b[0] = s->b[0];
     82   1.1   gdamore 	d->b[1] = s->b[1];
     83   1.1   gdamore 	d->b[2] = s->b[2];
     84   1.1   gdamore 	d->b[3] = s->b[3];
     85   1.1   gdamore 	d->b[4] = s->b[4];
     86   1.1   gdamore 	d->b[5] = s->b[5];
     87   1.1   gdamore }
     88   1.1   gdamore 
     89   1.1   gdamore /*
     90   1.1   gdamore  * Socket address used by Bluetooth protocols
     91   1.1   gdamore  */
     92   1.1   gdamore struct sockaddr_bt {
     93   1.1   gdamore 	uint8_t		bt_len;
     94   1.1   gdamore 	sa_family_t	bt_family;
     95   1.1   gdamore 	bdaddr_t	bt_bdaddr;
     96   1.1   gdamore 	uint16_t	bt_psm;
     97   1.1   gdamore 	uint8_t		bt_channel;
     98   1.1   gdamore 	uint8_t		bt_zero[5];
     99   1.1   gdamore };
    100   1.1   gdamore 
    101   1.1   gdamore /* Note: this is actually 6 bytes including terminator */
    102   1.1   gdamore #define BDADDR_ANY	((const bdaddr_t *) "\000\000\000\000\000")
    103   1.1   gdamore 
    104   1.1   gdamore #ifdef _KERNEL
    105   1.1   gdamore 
    106  1.12     rmind #include <sys/protosw.h>
    107  1.12     rmind 
    108  1.11     rmind #include <sys/mallocvar.h>
    109   1.1   gdamore MALLOC_DECLARE(M_BLUETOOTH);
    110   1.1   gdamore 
    111   1.1   gdamore /*
    112   1.1   gdamore  * Bluetooth Protocol API callback methods
    113   1.1   gdamore  */
    114   1.1   gdamore struct mbuf;
    115   1.1   gdamore struct btproto {
    116   1.1   gdamore 	void (*connecting)(void *);
    117   1.1   gdamore 	void (*connected)(void *);
    118   1.1   gdamore 	void (*disconnected)(void *, int);
    119   1.1   gdamore 	void *(*newconn)(void *, struct sockaddr_bt *, struct sockaddr_bt *);
    120   1.1   gdamore 	void (*complete)(void *, int);
    121   1.5    plunky 	void (*linkmode)(void *, int);
    122   1.1   gdamore 	void (*input)(void *, struct mbuf *);
    123   1.1   gdamore };
    124   1.1   gdamore 
    125  1.12     rmind extern const struct pr_usrreqs hci_usrreqs;
    126  1.12     rmind extern const struct pr_usrreqs sco_usrreqs;
    127  1.12     rmind extern const struct pr_usrreqs l2cap_usrreqs;
    128  1.12     rmind extern const struct pr_usrreqs rfcomm_usrreqs;
    129  1.12     rmind 
    130  1.12     rmind extern kmutex_t *bt_lock;
    131  1.12     rmind 
    132   1.1   gdamore /*
    133   1.1   gdamore  * Debugging stuff
    134   1.1   gdamore  */
    135   1.1   gdamore #ifdef BLUETOOTH_DEBUG
    136   1.1   gdamore extern int bluetooth_debug;
    137  1.10    plunky # define DPRINTF(...)	do {			\
    138  1.10    plunky 	if (bluetooth_debug) {			\
    139  1.10    plunky 		printf("%s: ", __func__);	\
    140  1.10    plunky 		printf(__VA_ARGS__);		\
    141  1.10    plunky 	}					\
    142   1.1   gdamore } while (/* CONSTCOND */0)
    143   1.1   gdamore 
    144  1.10    plunky # define DPRINTFN(n, ...)	do {		\
    145  1.10    plunky 	if (bluetooth_debug > (n)) {		\
    146  1.10    plunky 		printf("%s: ", __func__);	\
    147  1.10    plunky 		printf(__VA_ARGS__);		\
    148  1.10    plunky 	}					\
    149   1.1   gdamore } while (/* CONSTCOND */0)
    150   1.1   gdamore 
    151   1.1   gdamore # define UNKNOWN(value)			\
    152   1.1   gdamore 		printf("%s: %s = %d unknown!\n", __func__, #value, (value));
    153   1.1   gdamore #else
    154   1.6    rillig # define DPRINTF(...) ((void)0)
    155   1.6    rillig # define DPRINTFN(...) ((void)0)
    156   1.6    rillig # define UNKNOWN(x) ((void)0)
    157   1.1   gdamore #endif	/* BLUETOOTH_DEBUG */
    158   1.1   gdamore 
    159   1.1   gdamore #endif	/* _KERNEL */
    160   1.1   gdamore 
    161   1.1   gdamore #endif	/* _NETBT_BLUETOOTH_H_ */
    162