xref: /freebsd/lib/libbluetooth/bluetooth.h (revision 55034c7d1d465a5f79c2f80cbced395be852e2ee)
10986ab12SMaksim Yevmenkin /*
20986ab12SMaksim Yevmenkin  * bluetooth.h
30986ab12SMaksim Yevmenkin  *
40986ab12SMaksim Yevmenkin  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
50986ab12SMaksim Yevmenkin  * All rights reserved.
60986ab12SMaksim Yevmenkin  *
70986ab12SMaksim Yevmenkin  * Redistribution and use in source and binary forms, with or without
80986ab12SMaksim Yevmenkin  * modification, are permitted provided that the following conditions
90986ab12SMaksim Yevmenkin  * are met:
100986ab12SMaksim Yevmenkin  * 1. Redistributions of source code must retain the above copyright
110986ab12SMaksim Yevmenkin  *    notice, this list of conditions and the following disclaimer.
120986ab12SMaksim Yevmenkin  * 2. Redistributions in binary form must reproduce the above copyright
130986ab12SMaksim Yevmenkin  *    notice, this list of conditions and the following disclaimer in the
140986ab12SMaksim Yevmenkin  *    documentation and/or other materials provided with the distribution.
150986ab12SMaksim Yevmenkin  *
160986ab12SMaksim Yevmenkin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170986ab12SMaksim Yevmenkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180986ab12SMaksim Yevmenkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190986ab12SMaksim Yevmenkin  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200986ab12SMaksim Yevmenkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210986ab12SMaksim Yevmenkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220986ab12SMaksim Yevmenkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230986ab12SMaksim Yevmenkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240986ab12SMaksim Yevmenkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250986ab12SMaksim Yevmenkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260986ab12SMaksim Yevmenkin  * SUCH DAMAGE.
270986ab12SMaksim Yevmenkin  *
280986ab12SMaksim Yevmenkin  * $Id: bluetooth.h,v 1.5 2003/09/14 23:28:42 max Exp $
290986ab12SMaksim Yevmenkin  * $FreeBSD$
300986ab12SMaksim Yevmenkin  */
310986ab12SMaksim Yevmenkin 
320986ab12SMaksim Yevmenkin #ifndef _BLUETOOTH_H_
330986ab12SMaksim Yevmenkin #define _BLUETOOTH_H_
340986ab12SMaksim Yevmenkin 
350986ab12SMaksim Yevmenkin #include <sys/types.h>
360986ab12SMaksim Yevmenkin #include <sys/bitstring.h>
370986ab12SMaksim Yevmenkin #include <sys/endian.h>
380986ab12SMaksim Yevmenkin #include <sys/socket.h>
390986ab12SMaksim Yevmenkin #include <sys/un.h>
400986ab12SMaksim Yevmenkin #include <netdb.h>
410986ab12SMaksim Yevmenkin #include <netgraph/bluetooth/include/ng_hci.h>
420986ab12SMaksim Yevmenkin #include <netgraph/bluetooth/include/ng_l2cap.h>
430986ab12SMaksim Yevmenkin #include <netgraph/bluetooth/include/ng_btsocket.h>
440986ab12SMaksim Yevmenkin 
450986ab12SMaksim Yevmenkin __BEGIN_DECLS
460986ab12SMaksim Yevmenkin 
470986ab12SMaksim Yevmenkin /*
48738473e4SMaksim Yevmenkin  * Linux BlueZ compatibility
490986ab12SMaksim Yevmenkin  */
500986ab12SMaksim Yevmenkin 
510986ab12SMaksim Yevmenkin #define	bacmp(ba1, ba2)	memcmp((ba1), (ba2), sizeof(bdaddr_t))
520986ab12SMaksim Yevmenkin #define	bacpy(dst, src)	memcpy((dst), (src), sizeof(bdaddr_t))
530986ab12SMaksim Yevmenkin #define ba2str(ba, str)	bt_ntoa((ba), (str))
540986ab12SMaksim Yevmenkin #define str2ba(str, ba)	(bt_aton((str), (ba)) == 1? 0 : -1)
550986ab12SMaksim Yevmenkin 
560986ab12SMaksim Yevmenkin /*
570986ab12SMaksim Yevmenkin  * Interface to the outside world
580986ab12SMaksim Yevmenkin  */
590986ab12SMaksim Yevmenkin 
600986ab12SMaksim Yevmenkin struct hostent *  bt_gethostbyname    (char const *name);
610986ab12SMaksim Yevmenkin struct hostent *  bt_gethostbyaddr    (char const *addr, int len, int type);
620986ab12SMaksim Yevmenkin struct hostent *  bt_gethostent       (void);
630986ab12SMaksim Yevmenkin void              bt_sethostent       (int stayopen);
640986ab12SMaksim Yevmenkin void              bt_endhostent       (void);
650986ab12SMaksim Yevmenkin 
660986ab12SMaksim Yevmenkin struct protoent * bt_getprotobyname   (char const *name);
670986ab12SMaksim Yevmenkin struct protoent * bt_getprotobynumber (int proto);
680986ab12SMaksim Yevmenkin struct protoent * bt_getprotoent      (void);
690986ab12SMaksim Yevmenkin void              bt_setprotoent      (int stayopen);
700986ab12SMaksim Yevmenkin void              bt_endprotoent      (void);
710986ab12SMaksim Yevmenkin 
720986ab12SMaksim Yevmenkin char const *      bt_ntoa             (bdaddr_t const *ba, char *str);
730986ab12SMaksim Yevmenkin int               bt_aton             (char const *str, bdaddr_t *ba);
740986ab12SMaksim Yevmenkin 
7555034c7dSMaksim Yevmenkin /*
7655034c7dSMaksim Yevmenkin  * bdaddr utility functions (from NetBSD)
7755034c7dSMaksim Yevmenkin  */
7855034c7dSMaksim Yevmenkin 
7955034c7dSMaksim Yevmenkin static __inline int
8055034c7dSMaksim Yevmenkin bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
8155034c7dSMaksim Yevmenkin {
8255034c7dSMaksim Yevmenkin 	return (a->b[0] == b->b[0] && a->b[1] == b->b[1] &&
8355034c7dSMaksim Yevmenkin 		a->b[2] == b->b[2] && a->b[3] == b->b[3] &&
8455034c7dSMaksim Yevmenkin 		a->b[4] == b->b[4] && a->b[5] == b->b[5]);
8555034c7dSMaksim Yevmenkin }
8655034c7dSMaksim Yevmenkin 
8755034c7dSMaksim Yevmenkin static __inline int
8855034c7dSMaksim Yevmenkin bdaddr_any(const bdaddr_t *a)
8955034c7dSMaksim Yevmenkin {
9055034c7dSMaksim Yevmenkin 	return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 &&
9155034c7dSMaksim Yevmenkin 		a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
9255034c7dSMaksim Yevmenkin }
9355034c7dSMaksim Yevmenkin 
9455034c7dSMaksim Yevmenkin static __inline void
9555034c7dSMaksim Yevmenkin bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
9655034c7dSMaksim Yevmenkin {
9755034c7dSMaksim Yevmenkin 	d->b[0] = s->b[0];
9855034c7dSMaksim Yevmenkin 	d->b[1] = s->b[1];
9955034c7dSMaksim Yevmenkin 	d->b[2] = s->b[2];
10055034c7dSMaksim Yevmenkin 	d->b[3] = s->b[3];
10155034c7dSMaksim Yevmenkin 	d->b[4] = s->b[4];
10255034c7dSMaksim Yevmenkin 	d->b[5] = s->b[5];
10355034c7dSMaksim Yevmenkin }
10455034c7dSMaksim Yevmenkin 
1050986ab12SMaksim Yevmenkin __END_DECLS
1060986ab12SMaksim Yevmenkin 
1070986ab12SMaksim Yevmenkin #endif /* ndef _BLUETOOTH_H_ */
1080986ab12SMaksim Yevmenkin 
109