summaryrefslogtreecommitdiffstats
path: root/lib/libbluetooth
diff options
context:
space:
mode:
authoremax <emax@FreeBSD.org>2008-08-13 19:35:31 +0000
committeremax <emax@FreeBSD.org>2008-08-13 19:35:31 +0000
commit4474d60a02a72cfcd3a1662c95af5fcc844d13d0 (patch)
treec236468ebf274a689bf171a115862588b700bb15 /lib/libbluetooth
parent39084a201d11f684ca4c324e1cfe7c542655253f (diff)
downloadFreeBSD-src-4474d60a02a72cfcd3a1662c95af5fcc844d13d0.zip
FreeBSD-src-4474d60a02a72cfcd3a1662c95af5fcc844d13d0.tar.gz
Import handy shorthand Bluetooth address (BD_ADDR) utility functions
from NetBSD and document them. Obtained from: NetBSD MFC after: 1 week
Diffstat (limited to 'lib/libbluetooth')
-rw-r--r--lib/libbluetooth/Makefile4
-rw-r--r--lib/libbluetooth/bluetooth.335
-rw-r--r--lib/libbluetooth/bluetooth.h30
3 files changed, 67 insertions, 2 deletions
diff --git a/lib/libbluetooth/Makefile b/lib/libbluetooth/Makefile
index 0f85eff..30c55b8 100644
--- a/lib/libbluetooth/Makefile
+++ b/lib/libbluetooth/Makefile
@@ -27,4 +27,8 @@ MLINKS+= bluetooth.3 bt_endprotoent.3
MLINKS+= bluetooth.3 bt_ntoa.3
MLINKS+= bluetooth.3 bt_aton.3
+MLINKS+= bluetooth.3 bdaddr_same.3
+MLINKS+= bluetooth.3 bdaddr_any.3
+MLINKS+= bluetooth.3 bdaddr_copy.3
+
.include <bsd.lib.mk>
diff --git a/lib/libbluetooth/bluetooth.3 b/lib/libbluetooth/bluetooth.3
index d6adb26..c6a0dc3 100644
--- a/lib/libbluetooth/bluetooth.3
+++ b/lib/libbluetooth/bluetooth.3
@@ -25,7 +25,7 @@
.\" $Id: bluetooth.3,v 1.5 2003/05/20 23:04:30 max Exp $
.\" $FreeBSD$
.\"
-.Dd May 7, 2003
+.Dd August 13, 2008
.Dt BLUETOOTH 3
.Os
.Sh NAME
@@ -40,7 +40,10 @@
.Nm bt_setprotoent ,
.Nm bt_endprotoent ,
.Nm bt_aton ,
-.Nm bt_ntoa
+.Nm bt_ntoa ,
+.Nm bdaddr_same ,
+.Nm bdaddr_any ,
+.Nm bdaddr_copy
.Nd Bluetooth routines
.Sh LIBRARY
.Lb libbluetooth
@@ -70,6 +73,12 @@
.Fn bt_aton "const char *str" "bdaddr_t *ba"
.Ft const char *
.Fn bt_ntoa "const bdaddr_t *ba" "char *str"
+.Ft int
+.Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
+.Ft int
+.Fn bdaddr_any "const bdaddr_t *a"
+.Ft int
+.Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
.Sh DESCRIPTION
The
.Fn bt_gethostent ,
@@ -186,6 +195,28 @@ takes a Bluetooth address and places an
string representing the address into the buffer provided.
It is up to the caller to ensure that provided buffer has enough space.
If no buffer was provided then internal static buffer will be used.
+.Pp
+The
+.Fn bdaddr_same ,
+.Fn bdaddr_any
+and
+.Fn bdaddr_copy
+are handy shorthand Bluetooth address utility functions.
+The
+.Fn bdaddr_same
+function will test if two provided BD_ADDRs are the same.
+The
+.Fn bdaddr_any
+function will test if provided BD_ADDR is
+.Dv ANY
+BD_ADDR.
+The
+.Fn bdaddr_copy
+function will copy provided
+.Fa src
+BD_ADDR into provided
+.Fa dst
+BD_ADDR.
.Sh FILES
.Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
.It Pa /etc/bluetooth/hosts
diff --git a/lib/libbluetooth/bluetooth.h b/lib/libbluetooth/bluetooth.h
index d979787..0b62466 100644
--- a/lib/libbluetooth/bluetooth.h
+++ b/lib/libbluetooth/bluetooth.h
@@ -72,6 +72,36 @@ void bt_endprotoent (void);
char const * bt_ntoa (bdaddr_t const *ba, char *str);
int bt_aton (char const *str, bdaddr_t *ba);
+/*
+ * bdaddr utility functions (from NetBSD)
+ */
+
+static __inline int
+bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
+{
+ return (a->b[0] == b->b[0] && a->b[1] == b->b[1] &&
+ a->b[2] == b->b[2] && a->b[3] == b->b[3] &&
+ a->b[4] == b->b[4] && a->b[5] == b->b[5]);
+}
+
+static __inline int
+bdaddr_any(const bdaddr_t *a)
+{
+ return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 &&
+ a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
+}
+
+static __inline void
+bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
+{
+ d->b[0] = s->b[0];
+ d->b[1] = s->b[1];
+ d->b[2] = s->b[2];
+ d->b[3] = s->b[3];
+ d->b[4] = s->b[4];
+ d->b[5] = s->b[5];
+}
+
__END_DECLS
#endif /* ndef _BLUETOOTH_H_ */
OpenPOWER on IntegriCloud