From ee6756da8f73037037385aee8e3de1f175a4f969 Mon Sep 17 00:00:00 2001 From: Maksim Yevmenkin Date: Thu, 28 Aug 2008 21:23:50 +0000 Subject: [PATCH] MFC SVN rev 181698 Import handy shorthand Bluetooth address (BD_ADDR) utility functions from NetBSD and document them. Obtained from: NetBSD --- lib/libbluetooth/Makefile | 4 ++++ lib/libbluetooth/bluetooth.3 | 35 +++++++++++++++++++++++++++++++++-- lib/libbluetooth/bluetooth.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/lib/libbluetooth/Makefile b/lib/libbluetooth/Makefile index 0f85eff47fdf..30c55b87930b 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 diff --git a/lib/libbluetooth/bluetooth.3 b/lib/libbluetooth/bluetooth.3 index d6adb260392f..c6a0dc3e4c1e 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 d9797876e790..0b62466e8ccd 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_ */