2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
4 * All rights reserved. Distributed under the terms of the MIT License.
6 #ifndef _BDADDR_UTILS_H
7 #define _BDADDR_UTILS_H
14 #include <bluetooth/bluetooth.h>
21 static inline bdaddr_t
NullAddress()
23 return ((bdaddr_t
) {{0, 0, 0, 0, 0, 0}});
27 static inline bdaddr_t
LocalAddress()
29 return ((bdaddr_t
) {{0, 0, 0, 0xff, 0xff, 0xff}});
33 static inline bdaddr_t
BroadcastAddress()
35 return ((bdaddr_t
) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}});
39 static bool Compare(const bdaddr_t
& ba1
, const bdaddr_t
& ba2
)
41 return (memcmp(&ba1
, &ba2
, sizeof(bdaddr_t
)) == 0);
45 static void Copy(bdaddr_t
& dst
, const bdaddr_t
& src
)
47 memcpy(&dst
, &src
, sizeof(bdaddr_t
));
50 static BString
ToString(const bdaddr_t bdaddr
)
54 str
.SetToFormat("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",bdaddr
.b
[5],
55 bdaddr
.b
[4], bdaddr
.b
[3], bdaddr
.b
[2], bdaddr
.b
[1],
61 static bdaddr_t
FromString(const char * addr
)
63 uint8 b0
, b1
, b2
, b3
, b4
, b5
;
66 size_t count
= sscanf(addr
, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
67 &b5
, &b4
, &b3
, &b2
, &b1
, &b0
);
70 return ((bdaddr_t
) {{b0
, b1
, b2
, b3
, b4
, b5
}});
81 #ifndef _BT_USE_EXPLICIT_NAMESPACE
82 using Bluetooth::bdaddrUtils
;
86 #endif // _BDADDR_UTILS_H