Home | History | Annotate | Line # | Download | only in libbluetooth
bluetooth.h revision 1.3
      1 /*	$NetBSD: bluetooth.h,v 1.3 2006/09/26 19:18:19 plunky Exp $	*/
      2 
      3 /*
      4  * bluetooth.h
      5  *
      6  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  *
     30  * $Id: bluetooth.h,v 1.3 2006/09/26 19:18:19 plunky Exp $
     31  * $FreeBSD: src/lib/libbluetooth/bluetooth.h,v 1.2 2005/03/17 21:39:44 emax Exp $
     32  */
     33 
     34 #ifndef _BLUETOOTH_H_
     35 #define _BLUETOOTH_H_
     36 
     37 #include <sys/types.h>
     38 #include <sys/endian.h>
     39 #include <sys/socket.h>
     40 #include <netdb.h>
     41 #include <netbt/bluetooth.h>
     42 #include <netbt/hci.h>
     43 #include <netbt/l2cap.h>
     44 #include <stdio.h>
     45 
     46 __BEGIN_DECLS
     47 
     48 /*
     49  * Interface to the outside world
     50  */
     51 
     52 struct hostent *  bt_gethostbyname    (char const *);
     53 struct hostent *  bt_gethostbyaddr    (char const *, socklen_t, int);
     54 struct hostent *  bt_gethostent       (void);
     55 void              bt_sethostent       (int);
     56 void              bt_endhostent       (void);
     57 
     58 struct protoent * bt_getprotobyname   (char const *);
     59 struct protoent * bt_getprotobynumber (int);
     60 struct protoent * bt_getprotoent      (void);
     61 void              bt_setprotoent      (int);
     62 void              bt_endprotoent      (void);
     63 
     64 char const *      bt_ntoa             (bdaddr_t const *, char *);
     65 int               bt_aton             (char const *, bdaddr_t *);
     66 
     67 int               bt_devaddr          (const char *, bdaddr_t *);
     68 int               bt_devname          (char *, const bdaddr_t *);
     69 
     70 /*
     71  * bthcid(8) PIN Client API
     72  */
     73 
     74 /* Client PIN Request packet */
     75 typedef struct {
     76 	bdaddr_t	laddr;			/* local address */
     77 	bdaddr_t	raddr;			/* remote address */
     78 	uint8_t		time;			/* validity (seconds) */
     79 } __attribute__ ((packed)) bthcid_pin_request_t;
     80 
     81 /* Client PIN Response packet */
     82 typedef struct {
     83 	bdaddr_t	laddr;			/* local address */
     84 	bdaddr_t	raddr;			/* remote address */
     85 	uint8_t		pin[HCI_PIN_SIZE];	/* PIN */
     86 } __attribute__ ((packed)) bthcid_pin_response_t;
     87 
     88 /* Default socket name */
     89 #define BTHCID_SOCKET_NAME	"/var/run/bthcid"
     90 
     91 #ifdef COMPAT_BLUEZ
     92 /*
     93  * Linux BlueZ compatibility
     94  */
     95 
     96 #define	bacmp(ba1, ba2)	memcmp((ba1), (ba2), sizeof(bdaddr_t))
     97 #define	bacpy(dst, src)	memcpy((dst), (src), sizeof(bdaddr_t))
     98 #define ba2str(ba, str)	bt_ntoa((ba), (str))
     99 #define str2ba(str, ba)	(bt_aton((str), (ba)) == 1 ? 0 : -1)
    100 
    101 #define htobs(x)	htole16(x)
    102 #define htobl(x)	htole32(x)
    103 #define btohs(x)	le16toh(x)
    104 #define btohl(x)	le32toh(x)
    105 
    106 #define bt_malloc(n)	malloc(n)
    107 #define bt_free(p)	free(p)
    108 
    109 #endif	/* COMPAT_BLUEZ */
    110 
    111 __END_DECLS
    112 
    113 #endif /* ndef _BLUETOOTH_H_ */
    114