diff --git a/headers/os/bluetooth/HCI/btHCI_event.h b/headers/os/bluetooth/HCI/btHCI_event.h index fbbbbd9087..92bb21b102 100644 --- a/headers/os/bluetooth/HCI/btHCI_event.h +++ b/headers/os/bluetooth/HCI/btHCI_event.h @@ -1,5 +1,6 @@ /* * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com * * All rights reserved. Distributed under the terms of the MIT License. * @@ -170,7 +171,7 @@ struct hci_ev_mode_change { #define HCI_EVENT_RETURN_LINK_KEYS 0x15 struct link_key_info { bdaddr_t bdaddr; - uint8 link_key[HCI_LINK_KEY_SIZE]; + linkkey_t link_key; } __attribute__ ((packed)) ; struct hci_ev_return_link_keys { uint8 num_keys; /* # of keys */ @@ -190,7 +191,7 @@ struct hci_ev_link_key_req { #define HCI_EVENT_LINK_KEY_NOTIFY 0x18 struct hci_ev_link_key_notify { bdaddr_t bdaddr; - uint8 link_key[16]; + linkkey_t link_key; uint8 key_type; } __attribute__ ((packed)); diff --git a/headers/os/bluetooth/LinkKeyUtils.h b/headers/os/bluetooth/LinkKeyUtils.h new file mode 100644 index 0000000000..e3b6dd6e71 --- /dev/null +++ b/headers/os/bluetooth/LinkKeyUtils.h @@ -0,0 +1,73 @@ +/* + * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _LINKKEY_UTILS_H +#define _LINKKEY_UTILS_H + +#include + +#include + + +namespace Bluetooth { + +class LinkKeyUtils { +public: + static bool Compare(linkkey_t* lk1, linkkey_t* lk2) + { + return (memcmp(lk1, lk2, sizeof(linkkey_t)) == 0); + } + + static linkkey_t NullKey() + { + return (linkkey_t) {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + } + + static char* ToString(const linkkey_t lk) + { + + // TODO: not safe + static char str[50]; + + sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:" + "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", + lk.l[0], lk.l[1], lk.l[2], lk.l[3], + lk.l[4], lk.l[5], lk.l[6], lk.l[7], + lk.l[8], lk.l[9], lk.l[10], lk.l[11], + lk.l[12], lk.l[13], lk.l[14], lk.l[15]); + + return str; + } + + static linkkey_t FromString(const char *lkstr) + { + if (lkstr != NULL) + { + int l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15; + size_t count = sscanf(lkstr, "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X:" + "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X", + &l0, &l1, &l2, &l3, &l4, &l5, &l6, &l7, + &l8, &l9, &l10, &l11, &l12, &l13, &l14, &l15); + + if (count == 16) + { + return (linkkey_t) {{l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15}}; + } + } + + return NullKey(); + + } +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::LinkKeyUtils; +#endif + +#endif \ No newline at end of file diff --git a/headers/os/bluetooth/bluetooth.h b/headers/os/bluetooth/bluetooth.h index ba76003f95..74842fd2ef 100644 --- a/headers/os/bluetooth/bluetooth.h +++ b/headers/os/bluetooth/bluetooth.h @@ -1,5 +1,6 @@ /* * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com * * All rights reserved. Distributed under the terms of the MIT License. * @@ -11,12 +12,12 @@ #include /* Bluetooth version */ -#define BLUETOOTH_1_1B 0 -#define BLUETOOTH_1_1 1 -#define BLUETOOTH_1_2 2 -#define BLUETOOTH_2_0 3 +#define BLUETOOTH_1_1B 0 +#define BLUETOOTH_1_1 1 +#define BLUETOOTH_1_2 2 +#define BLUETOOTH_2_0 3 -#define BLUETOOTH_VERSION BLUETOOTH_2_0 +#define BLUETOOTH_VERSION BLUETOOTH_2_0 /* Bluetooth common types */ @@ -27,10 +28,17 @@ typedef struct { } __attribute__((packed)) bdaddr_t; -#define BDADDR_NULL (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) -#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) -#define BDADDR_BROADCAST (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) -#define BDADDR_ANY BDADDR_BROADCAST +#define BDADDR_NULL (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) +#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) +#define BDADDR_BROADCAST (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) +#define BDADDR_ANY BDADDR_BROADCAST + + +/* Link key */ +typedef struct { + uint8 l[16]; +} __attribute__((packed)) linkkey_t; + /* 128 integer type needed for SDP */ struct int128 { @@ -44,7 +52,7 @@ typedef struct int128 uint128; #define BLUETOOTH_PROTO_L2CAP 135 /* L2CAP protocol number */ #define BLUETOOTH_PROTO_RFCOMM 136 /* RFCOMM protocol number */ -#define BLUETOOTH_PROTO_MAX 256 +#define BLUETOOTH_PROTO_MAX 256 #endif