1*22670c85Sjoerg /* $NetBSD: bluetooth.h,v 1.5 2011/11/28 12:44:18 joerg Exp $ */ 2a5c89047Sgdamore 3bd42c2e8Splunky /*- 4bd42c2e8Splunky * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5a5c89047Sgdamore * All rights reserved. 6a5c89047Sgdamore * 7a5c89047Sgdamore * Redistribution and use in source and binary forms, with or without 8a5c89047Sgdamore * modification, are permitted provided that the following conditions 9a5c89047Sgdamore * are met: 10a5c89047Sgdamore * 1. Redistributions of source code must retain the above copyright 11a5c89047Sgdamore * notice, this list of conditions and the following disclaimer. 12a5c89047Sgdamore * 2. Redistributions in binary form must reproduce the above copyright 13a5c89047Sgdamore * notice, this list of conditions and the following disclaimer in the 14a5c89047Sgdamore * documentation and/or other materials provided with the distribution. 15a5c89047Sgdamore * 16a5c89047Sgdamore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17a5c89047Sgdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18a5c89047Sgdamore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19a5c89047Sgdamore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20a5c89047Sgdamore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21a5c89047Sgdamore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22a5c89047Sgdamore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23a5c89047Sgdamore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24a5c89047Sgdamore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25a5c89047Sgdamore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26a5c89047Sgdamore * SUCH DAMAGE. 27a5c89047Sgdamore * 28bd42c2e8Splunky * $FreeBSD: src/lib/libbluetooth/bluetooth.h,v 1.5 2009/04/22 15:50:03 emax Exp $ 29a5c89047Sgdamore */ 30a5c89047Sgdamore 31a5c89047Sgdamore #ifndef _BLUETOOTH_H_ 32a5c89047Sgdamore #define _BLUETOOTH_H_ 33a5c89047Sgdamore 34a5c89047Sgdamore #include <sys/types.h> 35a5c89047Sgdamore #include <sys/endian.h> 36a5c89047Sgdamore #include <sys/socket.h> 37bd42c2e8Splunky 38a5c89047Sgdamore #include <netbt/bluetooth.h> 39a5c89047Sgdamore #include <netbt/hci.h> 40a5c89047Sgdamore #include <netbt/l2cap.h> 41bd42c2e8Splunky 42bd42c2e8Splunky #include <netdb.h> 43a5c89047Sgdamore #include <stdio.h> 44bd42c2e8Splunky #include <time.h> 45a5c89047Sgdamore 46a5c89047Sgdamore __BEGIN_DECLS 47a5c89047Sgdamore 48a5c89047Sgdamore /* 49a5c89047Sgdamore * Interface to the outside world 50a5c89047Sgdamore */ 51a5c89047Sgdamore 52a5c89047Sgdamore struct hostent * bt_gethostbyname (char const *); 53a5c89047Sgdamore struct hostent * bt_gethostbyaddr (char const *, socklen_t, int); 54a5c89047Sgdamore struct hostent * bt_gethostent (void); 55a5c89047Sgdamore void bt_sethostent (int); 56a5c89047Sgdamore void bt_endhostent (void); 57a5c89047Sgdamore 58a5c89047Sgdamore struct protoent * bt_getprotobyname (char const *); 59a5c89047Sgdamore struct protoent * bt_getprotobynumber (int); 60a5c89047Sgdamore struct protoent * bt_getprotoent (void); 61a5c89047Sgdamore void bt_setprotoent (int); 62a5c89047Sgdamore void bt_endprotoent (void); 63a5c89047Sgdamore 64a5c89047Sgdamore char const * bt_ntoa (bdaddr_t const *, char *); 65a5c89047Sgdamore int bt_aton (char const *, bdaddr_t *); 66a5c89047Sgdamore 67bd42c2e8Splunky /* 68bd42c2e8Splunky * Bluetooth device access API 69bd42c2e8Splunky */ 70bd42c2e8Splunky 71bd42c2e8Splunky struct bt_devinfo { 72bd42c2e8Splunky char devname[HCI_DEVNAME_SIZE]; 73bd42c2e8Splunky int enabled; /* device is enabled */ 74bd42c2e8Splunky 75bd42c2e8Splunky /* device information */ 76bd42c2e8Splunky bdaddr_t bdaddr; 77bd42c2e8Splunky uint8_t features[HCI_FEATURES_SIZE]; 78bd42c2e8Splunky uint16_t acl_size; /* max ACL data size */ 79bd42c2e8Splunky uint16_t acl_pkts; /* total ACL packet buffers */ 80bd42c2e8Splunky uint16_t sco_size; /* max SCO data size */ 81bd42c2e8Splunky uint16_t sco_pkts; /* total SCO packet buffers */ 82bd42c2e8Splunky 83bd42c2e8Splunky /* flow control */ 84bd42c2e8Splunky uint16_t cmd_free; /* available CMD packet buffers */ 85bd42c2e8Splunky uint16_t acl_free; /* available ACL packet buffers */ 86bd42c2e8Splunky uint16_t sco_free; /* available SCO packet buffers */ 87bd42c2e8Splunky 88bd42c2e8Splunky /* statistics */ 89bd42c2e8Splunky uint32_t cmd_sent; 90bd42c2e8Splunky uint32_t evnt_recv; 91bd42c2e8Splunky uint32_t acl_recv; 92bd42c2e8Splunky uint32_t acl_sent; 93bd42c2e8Splunky uint32_t sco_recv; 94bd42c2e8Splunky uint32_t sco_sent; 95bd42c2e8Splunky uint32_t bytes_recv; 96bd42c2e8Splunky uint32_t bytes_sent; 97bd42c2e8Splunky 98bd42c2e8Splunky /* device settings */ 99bd42c2e8Splunky uint16_t link_policy_info; 100bd42c2e8Splunky uint16_t packet_type_info; 101bd42c2e8Splunky uint16_t role_switch_info; 102bd42c2e8Splunky }; 103bd42c2e8Splunky 104bd42c2e8Splunky struct bt_devreq { 105bd42c2e8Splunky uint16_t opcode; 106bd42c2e8Splunky uint8_t event; 107bd42c2e8Splunky void *cparam; 108bd42c2e8Splunky size_t clen; 109bd42c2e8Splunky void *rparam; 110bd42c2e8Splunky size_t rlen; 111bd42c2e8Splunky }; 112bd42c2e8Splunky 113bd42c2e8Splunky struct bt_devfilter { 114bd42c2e8Splunky struct hci_filter packet_mask; 115bd42c2e8Splunky struct hci_filter event_mask; 116bd42c2e8Splunky }; 117bd42c2e8Splunky 118bd42c2e8Splunky struct bt_devinquiry { 119bd42c2e8Splunky bdaddr_t bdaddr; 120bd42c2e8Splunky uint8_t pscan_rep_mode; 121bd42c2e8Splunky uint8_t pscan_period_mode; 122bd42c2e8Splunky uint8_t dev_class[3]; 123bd42c2e8Splunky uint16_t clock_offset; 124bd42c2e8Splunky int8_t rssi; 125bd42c2e8Splunky uint8_t data[240]; 126bd42c2e8Splunky }; 127bd42c2e8Splunky 128bd42c2e8Splunky /* bt_devopen() flags */ 129bd42c2e8Splunky #define BTOPT_DIRECTION (1 << 0) 130bd42c2e8Splunky #define BTOPT_TIMESTAMP (1 << 1) 131bd42c2e8Splunky 132bd42c2e8Splunky /* compatibility */ 133bd42c2e8Splunky #define bt_devclose(s) close(s) 134bd42c2e8Splunky 135bd42c2e8Splunky typedef int (bt_devenum_cb_t)(int, const struct bt_devinfo *, void *); 136bd42c2e8Splunky 137a5c89047Sgdamore int bt_devaddr(const char *, bdaddr_t *); 138a5c89047Sgdamore int bt_devname(char *, const bdaddr_t *); 139bd42c2e8Splunky int bt_devopen(const char *, int); 140bd42c2e8Splunky ssize_t bt_devsend(int, uint16_t, void *, size_t); 141bd42c2e8Splunky ssize_t bt_devrecv(int, void *, size_t, time_t); 142bd42c2e8Splunky int bt_devreq(int, struct bt_devreq *, time_t); 143bd42c2e8Splunky int bt_devfilter(int, const struct bt_devfilter *, struct bt_devfilter *); 144bd42c2e8Splunky void bt_devfilter_pkt_set(struct bt_devfilter *, uint8_t); 145bd42c2e8Splunky void bt_devfilter_pkt_clr(struct bt_devfilter *, uint8_t); 146bd42c2e8Splunky int bt_devfilter_pkt_tst(const struct bt_devfilter *, uint8_t); 147bd42c2e8Splunky void bt_devfilter_evt_set(struct bt_devfilter *, uint8_t); 148bd42c2e8Splunky void bt_devfilter_evt_clr(struct bt_devfilter *, uint8_t); 149bd42c2e8Splunky int bt_devfilter_evt_tst(const struct bt_devfilter *, uint8_t); 150bd42c2e8Splunky int bt_devinquiry(const char *, time_t, int, struct bt_devinquiry **); 151bd42c2e8Splunky int bt_devinfo(const char *, struct bt_devinfo *); 152bd42c2e8Splunky int bt_devenum(bt_devenum_cb_t *, void *); 153a5c89047Sgdamore 1540b73a6ecSplunky /* 1550b73a6ecSplunky * bthcid(8) PIN Client API 1560b73a6ecSplunky */ 1570b73a6ecSplunky 1580b73a6ecSplunky /* Client PIN Request packet */ 1590b73a6ecSplunky typedef struct { 1600b73a6ecSplunky bdaddr_t laddr; /* local address */ 1610b73a6ecSplunky bdaddr_t raddr; /* remote address */ 1620b73a6ecSplunky uint8_t time; /* validity (seconds) */ 163*22670c85Sjoerg } __packed bthcid_pin_request_t; 1640b73a6ecSplunky 1650b73a6ecSplunky /* Client PIN Response packet */ 1660b73a6ecSplunky typedef struct { 1670b73a6ecSplunky bdaddr_t laddr; /* local address */ 1680b73a6ecSplunky bdaddr_t raddr; /* remote address */ 1690b73a6ecSplunky uint8_t pin[HCI_PIN_SIZE]; /* PIN */ 170*22670c85Sjoerg } __packed bthcid_pin_response_t; 1710b73a6ecSplunky 1720b73a6ecSplunky /* Default socket name */ 1730b73a6ecSplunky #define BTHCID_SOCKET_NAME "/var/run/bthcid" 1740b73a6ecSplunky 175a5c89047Sgdamore #ifdef COMPAT_BLUEZ 176a5c89047Sgdamore /* 177a5c89047Sgdamore * Linux BlueZ compatibility 178a5c89047Sgdamore */ 179a5c89047Sgdamore 180a5c89047Sgdamore #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t)) 181a5c89047Sgdamore #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t)) 182a5c89047Sgdamore #define ba2str(ba, str) bt_ntoa((ba), (str)) 183a5c89047Sgdamore #define str2ba(str, ba) (bt_aton((str), (ba)) == 1 ? 0 : -1) 184a5c89047Sgdamore 185a5c89047Sgdamore #define htobs(x) htole16(x) 186a5c89047Sgdamore #define htobl(x) htole32(x) 187a5c89047Sgdamore #define btohs(x) le16toh(x) 188a5c89047Sgdamore #define btohl(x) le32toh(x) 189a5c89047Sgdamore 190a5c89047Sgdamore #define bt_malloc(n) malloc(n) 191a5c89047Sgdamore #define bt_free(p) free(p) 192a5c89047Sgdamore 193a5c89047Sgdamore #endif /* COMPAT_BLUEZ */ 194a5c89047Sgdamore 195a5c89047Sgdamore __END_DECLS 196a5c89047Sgdamore 197a5c89047Sgdamore #endif /* ndef _BLUETOOTH_H_ */ 198