2002-03-09 05:10:06 +08:00
|
|
|
/*
|
2004-04-03 13:11:38 +08:00
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2001 Qualcomm Incorporated
|
|
|
|
* Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
|
2005-01-29 11:08:19 +08:00
|
|
|
* Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
|
2004-04-03 13:11:38 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
|
|
|
|
* CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
|
|
|
|
* COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
|
|
|
|
* SOFTWARE IS DISCLAIMED.
|
|
|
|
*
|
|
|
|
*
|
2002-03-09 05:10:06 +08:00
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BLUETOOTH_H
|
|
|
|
#define __BLUETOOTH_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <endian.h>
|
2002-03-13 02:58:39 +08:00
|
|
|
#include <byteswap.h>
|
2002-03-29 04:48:45 +08:00
|
|
|
#include <string.h>
|
2003-07-03 08:06:26 +08:00
|
|
|
|
2002-03-09 05:10:06 +08:00
|
|
|
#ifndef AF_BLUETOOTH
|
|
|
|
#define AF_BLUETOOTH 31
|
|
|
|
#define PF_BLUETOOTH AF_BLUETOOTH
|
|
|
|
#endif
|
|
|
|
|
2003-07-03 08:06:26 +08:00
|
|
|
#define BTPROTO_L2CAP 0
|
|
|
|
#define BTPROTO_HCI 1
|
|
|
|
#define BTPROTO_SCO 2
|
2002-03-09 05:10:06 +08:00
|
|
|
#define BTPROTO_RFCOMM 3
|
2002-05-07 04:54:32 +08:00
|
|
|
#define BTPROTO_BNEP 4
|
2003-06-05 14:38:18 +08:00
|
|
|
#define BTPROTO_CMTP 5
|
2004-03-09 23:39:56 +08:00
|
|
|
#define BTPROTO_HIDP 6
|
2004-07-04 23:38:11 +08:00
|
|
|
#define BTPROTO_AVDTP 7
|
2002-03-09 05:10:06 +08:00
|
|
|
|
2003-07-03 08:06:26 +08:00
|
|
|
#define SOL_HCI 0
|
|
|
|
#define SOL_L2CAP 6
|
|
|
|
#define SOL_SCO 17
|
|
|
|
#define SOL_RFCOMM 18
|
2002-03-09 05:10:06 +08:00
|
|
|
|
|
|
|
/* Connection and socket states */
|
|
|
|
enum {
|
|
|
|
BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
|
|
|
|
BT_OPEN,
|
|
|
|
BT_BOUND,
|
|
|
|
BT_LISTEN,
|
|
|
|
BT_CONNECT,
|
|
|
|
BT_CONNECT2,
|
|
|
|
BT_CONFIG,
|
|
|
|
BT_DISCONN,
|
|
|
|
BT_CLOSED
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Byte order conversions */
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#define htobs(d) (d)
|
|
|
|
#define htobl(d) (d)
|
|
|
|
#define btohs(d) (d)
|
|
|
|
#define btohl(d) (d)
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
#define htobs(d) bswap_16(d)
|
|
|
|
#define htobl(d) bswap_32(d)
|
|
|
|
#define btohs(d) bswap_16(d)
|
|
|
|
#define btohl(d) bswap_32(d)
|
|
|
|
#else
|
|
|
|
#error "Unknown byte order"
|
|
|
|
#endif
|
|
|
|
|
2004-04-03 16:25:58 +08:00
|
|
|
/* Bluetooth unaligned access */
|
2005-01-21 02:14:19 +08:00
|
|
|
#define bt_get_unaligned(ptr) \
|
|
|
|
({ \
|
|
|
|
struct __attribute__((packed)) { \
|
|
|
|
typeof(*(ptr)) __v; \
|
2005-01-23 22:36:19 +08:00
|
|
|
} *__p = (void *) (ptr); \
|
2005-01-21 02:14:19 +08:00
|
|
|
__p->__v; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define bt_put_unaligned(val, ptr) \
|
|
|
|
do { \
|
|
|
|
struct __attribute__((packed)) { \
|
|
|
|
typeof(*(ptr)) __v; \
|
2005-01-23 22:36:19 +08:00
|
|
|
} *__p = (void *) (ptr); \
|
2005-01-21 02:14:19 +08:00
|
|
|
__p->__v = (val); \
|
|
|
|
} while(0)
|
2004-04-03 16:25:58 +08:00
|
|
|
|
2002-03-09 05:10:06 +08:00
|
|
|
/* BD Address */
|
|
|
|
typedef struct {
|
|
|
|
uint8_t b[6];
|
|
|
|
} __attribute__((packed)) bdaddr_t;
|
|
|
|
|
2002-03-31 13:14:51 +08:00
|
|
|
#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
|
2004-05-09 03:52:55 +08:00
|
|
|
#define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
|
2002-03-31 13:14:51 +08:00
|
|
|
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
|
2002-03-09 05:10:06 +08:00
|
|
|
|
|
|
|
/* Copy, swap, convert BD Address */
|
2003-02-11 18:22:23 +08:00
|
|
|
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
|
2002-03-09 05:10:06 +08:00
|
|
|
{
|
|
|
|
return memcmp(ba1, ba2, sizeof(bdaddr_t));
|
|
|
|
}
|
2003-02-11 18:22:23 +08:00
|
|
|
static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
|
2002-03-09 05:10:06 +08:00
|
|
|
{
|
|
|
|
memcpy(dst, src, sizeof(bdaddr_t));
|
|
|
|
}
|
|
|
|
|
2003-02-11 18:22:23 +08:00
|
|
|
void baswap(bdaddr_t *dst, const bdaddr_t *src);
|
|
|
|
bdaddr_t *strtoba(const char *str);
|
2004-04-03 13:11:38 +08:00
|
|
|
char *batostr(const bdaddr_t *ba);
|
|
|
|
int ba2str(const bdaddr_t *ba, char *str);
|
|
|
|
int str2ba(const char *str, bdaddr_t *ba);
|
2002-03-09 05:10:06 +08:00
|
|
|
|
2004-04-03 13:11:38 +08:00
|
|
|
int bt_error(uint16_t code);
|
2002-03-22 07:20:32 +08:00
|
|
|
char *bt_compidtostr(int id);
|
2002-03-09 05:10:06 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __BLUETOOTH_H */
|