Home | History | Annotate | Line # | Download | only in libbluetooth
bluetooth.h revision 1.4.6.1
      1  1.4.6.1     yamt /*	$NetBSD: bluetooth.h,v 1.4.6.1 2012/04/17 00:05:12 yamt Exp $	*/
      2      1.1  gdamore 
      3      1.4   plunky /*-
      4      1.4   plunky  * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
      5      1.1  gdamore  * All rights reserved.
      6      1.1  gdamore  *
      7      1.1  gdamore  * Redistribution and use in source and binary forms, with or without
      8      1.1  gdamore  * modification, are permitted provided that the following conditions
      9      1.1  gdamore  * are met:
     10      1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     11      1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     12      1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     15      1.1  gdamore  *
     16      1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17      1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18      1.1  gdamore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19      1.1  gdamore  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20      1.1  gdamore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21      1.1  gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22      1.1  gdamore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23      1.1  gdamore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24      1.1  gdamore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1  gdamore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1  gdamore  * SUCH DAMAGE.
     27      1.1  gdamore  *
     28      1.4   plunky  * $FreeBSD: src/lib/libbluetooth/bluetooth.h,v 1.5 2009/04/22 15:50:03 emax Exp $
     29      1.1  gdamore  */
     30      1.1  gdamore 
     31      1.1  gdamore #ifndef _BLUETOOTH_H_
     32      1.1  gdamore #define _BLUETOOTH_H_
     33      1.1  gdamore 
     34      1.1  gdamore #include <sys/types.h>
     35      1.1  gdamore #include <sys/endian.h>
     36      1.1  gdamore #include <sys/socket.h>
     37      1.4   plunky 
     38      1.1  gdamore #include <netbt/bluetooth.h>
     39      1.1  gdamore #include <netbt/hci.h>
     40      1.1  gdamore #include <netbt/l2cap.h>
     41      1.4   plunky 
     42      1.4   plunky #include <netdb.h>
     43      1.1  gdamore #include <stdio.h>
     44      1.4   plunky #include <time.h>
     45      1.1  gdamore 
     46      1.1  gdamore __BEGIN_DECLS
     47      1.1  gdamore 
     48      1.1  gdamore /*
     49      1.1  gdamore  * Interface to the outside world
     50      1.1  gdamore  */
     51      1.1  gdamore 
     52      1.1  gdamore struct hostent *  bt_gethostbyname    (char const *);
     53      1.1  gdamore struct hostent *  bt_gethostbyaddr    (char const *, socklen_t, int);
     54      1.1  gdamore struct hostent *  bt_gethostent       (void);
     55      1.1  gdamore void              bt_sethostent       (int);
     56      1.1  gdamore void              bt_endhostent       (void);
     57      1.1  gdamore 
     58      1.1  gdamore struct protoent * bt_getprotobyname   (char const *);
     59      1.1  gdamore struct protoent * bt_getprotobynumber (int);
     60      1.1  gdamore struct protoent * bt_getprotoent      (void);
     61      1.1  gdamore void              bt_setprotoent      (int);
     62      1.1  gdamore void              bt_endprotoent      (void);
     63      1.1  gdamore 
     64      1.1  gdamore char const *      bt_ntoa             (bdaddr_t const *, char *);
     65      1.1  gdamore int               bt_aton             (char const *, bdaddr_t *);
     66      1.1  gdamore 
     67      1.4   plunky /*
     68      1.4   plunky  * Bluetooth device access API
     69      1.4   plunky  */
     70      1.4   plunky 
     71      1.4   plunky struct bt_devinfo {
     72      1.4   plunky 	char		devname[HCI_DEVNAME_SIZE];
     73      1.4   plunky 	int		enabled;	/* device is enabled */
     74      1.4   plunky 
     75      1.4   plunky 	/* device information */
     76      1.4   plunky 	bdaddr_t	bdaddr;
     77      1.4   plunky 	uint8_t		features[HCI_FEATURES_SIZE];
     78      1.4   plunky 	uint16_t	acl_size;	/* max ACL data size */
     79      1.4   plunky 	uint16_t	acl_pkts;	/* total ACL packet buffers */
     80      1.4   plunky 	uint16_t	sco_size;	/* max SCO data size */
     81      1.4   plunky 	uint16_t	sco_pkts;	/* total SCO packet buffers */
     82      1.4   plunky 
     83      1.4   plunky 	/* flow control */
     84      1.4   plunky 	uint16_t	cmd_free;	/* available CMD packet buffers */
     85      1.4   plunky 	uint16_t	acl_free;	/* available ACL packet buffers */
     86      1.4   plunky 	uint16_t	sco_free;	/* available SCO packet buffers */
     87      1.4   plunky 
     88      1.4   plunky 	/* statistics */
     89      1.4   plunky 	uint32_t	cmd_sent;
     90      1.4   plunky 	uint32_t	evnt_recv;
     91      1.4   plunky 	uint32_t	acl_recv;
     92      1.4   plunky 	uint32_t	acl_sent;
     93      1.4   plunky 	uint32_t	sco_recv;
     94      1.4   plunky 	uint32_t	sco_sent;
     95      1.4   plunky 	uint32_t	bytes_recv;
     96      1.4   plunky 	uint32_t	bytes_sent;
     97      1.4   plunky 
     98      1.4   plunky 	/* device settings */
     99      1.4   plunky 	uint16_t	link_policy_info;
    100      1.4   plunky 	uint16_t	packet_type_info;
    101      1.4   plunky 	uint16_t	role_switch_info;
    102      1.4   plunky };
    103      1.4   plunky 
    104      1.4   plunky struct bt_devreq {
    105      1.4   plunky 	uint16_t	opcode;
    106      1.4   plunky 	uint8_t		event;
    107      1.4   plunky 	void		*cparam;
    108      1.4   plunky 	size_t		clen;
    109      1.4   plunky 	void		*rparam;
    110      1.4   plunky 	size_t		rlen;
    111      1.4   plunky };
    112      1.4   plunky 
    113      1.4   plunky struct bt_devfilter {
    114      1.4   plunky 	struct hci_filter	packet_mask;
    115      1.4   plunky 	struct hci_filter	event_mask;
    116      1.4   plunky };
    117      1.4   plunky 
    118      1.4   plunky struct bt_devinquiry {
    119      1.4   plunky 	bdaddr_t        bdaddr;
    120      1.4   plunky 	uint8_t         pscan_rep_mode;
    121      1.4   plunky 	uint8_t         pscan_period_mode;
    122      1.4   plunky 	uint8_t         dev_class[3];
    123      1.4   plunky 	uint16_t        clock_offset;
    124      1.4   plunky 	int8_t          rssi;
    125      1.4   plunky 	uint8_t         data[240];
    126      1.4   plunky };
    127      1.4   plunky 
    128      1.4   plunky /* bt_devopen() flags */
    129      1.4   plunky #define	BTOPT_DIRECTION		(1 << 0)
    130      1.4   plunky #define	BTOPT_TIMESTAMP		(1 << 1)
    131      1.4   plunky 
    132      1.4   plunky /* compatibility */
    133      1.4   plunky #define	bt_devclose(s)		close(s)
    134      1.4   plunky 
    135      1.4   plunky typedef int (bt_devenum_cb_t)(int, const struct bt_devinfo *, void *);
    136      1.4   plunky 
    137      1.4   plunky int	bt_devaddr(const char *, bdaddr_t *);
    138      1.4   plunky int	bt_devname(char *, const bdaddr_t *);
    139      1.4   plunky int	bt_devopen(const char *, int);
    140      1.4   plunky ssize_t	bt_devsend(int, uint16_t, void *, size_t);
    141      1.4   plunky ssize_t	bt_devrecv(int, void *, size_t, time_t);
    142      1.4   plunky int	bt_devreq(int, struct bt_devreq *, time_t);
    143      1.4   plunky int	bt_devfilter(int, const struct bt_devfilter *, struct bt_devfilter *);
    144      1.4   plunky void	bt_devfilter_pkt_set(struct bt_devfilter *, uint8_t);
    145      1.4   plunky void	bt_devfilter_pkt_clr(struct bt_devfilter *, uint8_t);
    146      1.4   plunky int	bt_devfilter_pkt_tst(const struct bt_devfilter *, uint8_t);
    147      1.4   plunky void	bt_devfilter_evt_set(struct bt_devfilter *, uint8_t);
    148      1.4   plunky void	bt_devfilter_evt_clr(struct bt_devfilter *, uint8_t);
    149      1.4   plunky int	bt_devfilter_evt_tst(const struct bt_devfilter *, uint8_t);
    150      1.4   plunky int	bt_devinquiry(const char *, time_t, int, struct bt_devinquiry **);
    151      1.4   plunky int	bt_devinfo(const char *, struct bt_devinfo *);
    152      1.4   plunky int	bt_devenum(bt_devenum_cb_t *, void *);
    153      1.1  gdamore 
    154      1.3   plunky /*
    155      1.3   plunky  * bthcid(8) PIN Client API
    156      1.3   plunky  */
    157      1.3   plunky 
    158      1.3   plunky /* Client PIN Request packet */
    159      1.3   plunky typedef struct {
    160      1.3   plunky 	bdaddr_t	laddr;			/* local address */
    161      1.3   plunky 	bdaddr_t	raddr;			/* remote address */
    162      1.3   plunky 	uint8_t		time;			/* validity (seconds) */
    163  1.4.6.1     yamt } __packed bthcid_pin_request_t;
    164      1.3   plunky 
    165      1.3   plunky /* Client PIN Response packet */
    166      1.3   plunky typedef struct {
    167      1.3   plunky 	bdaddr_t	laddr;			/* local address */
    168      1.3   plunky 	bdaddr_t	raddr;			/* remote address */
    169      1.3   plunky 	uint8_t		pin[HCI_PIN_SIZE];	/* PIN */
    170  1.4.6.1     yamt } __packed bthcid_pin_response_t;
    171      1.3   plunky 
    172      1.3   plunky /* Default socket name */
    173      1.3   plunky #define BTHCID_SOCKET_NAME	"/var/run/bthcid"
    174      1.3   plunky 
    175      1.1  gdamore #ifdef COMPAT_BLUEZ
    176      1.1  gdamore /*
    177      1.1  gdamore  * Linux BlueZ compatibility
    178      1.1  gdamore  */
    179      1.1  gdamore 
    180      1.1  gdamore #define	bacmp(ba1, ba2)	memcmp((ba1), (ba2), sizeof(bdaddr_t))
    181      1.1  gdamore #define	bacpy(dst, src)	memcpy((dst), (src), sizeof(bdaddr_t))
    182      1.1  gdamore #define ba2str(ba, str)	bt_ntoa((ba), (str))
    183      1.1  gdamore #define str2ba(str, ba)	(bt_aton((str), (ba)) == 1 ? 0 : -1)
    184      1.1  gdamore 
    185      1.1  gdamore #define htobs(x)	htole16(x)
    186      1.1  gdamore #define htobl(x)	htole32(x)
    187      1.1  gdamore #define btohs(x)	le16toh(x)
    188      1.1  gdamore #define btohl(x)	le32toh(x)
    189      1.1  gdamore 
    190      1.1  gdamore #define bt_malloc(n)	malloc(n)
    191      1.1  gdamore #define bt_free(p)	free(p)
    192      1.1  gdamore 
    193      1.1  gdamore #endif	/* COMPAT_BLUEZ */
    194      1.1  gdamore 
    195      1.1  gdamore __END_DECLS
    196      1.1  gdamore 
    197      1.1  gdamore #endif /* ndef _BLUETOOTH_H_ */
    198