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>
|
2010-01-02 09:08:17 +08:00
|
|
|
* Copyright (C) 2002-2010 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
|
2005-10-30 03:25:42 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2004-04-03 13:11:38 +08:00
|
|
|
*
|
2005-10-30 03:25:42 +08:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2004-04-03 13:11:38 +08:00
|
|
|
*
|
2005-10-30 03:25:42 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-04-03 13:11:38 +08:00
|
|
|
*
|
2002-03-09 05:10:06 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BLUETOOTH_H
|
|
|
|
#define __BLUETOOTH_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 20:23:13 +08:00
|
|
|
#include <stdio.h>
|
2002-03-09 05:10:06 +08:00
|
|
|
#include <stdint.h>
|
2005-03-27 22:37:59 +08:00
|
|
|
#include <string.h>
|
2002-03-09 05:10:06 +08:00
|
|
|
#include <endian.h>
|
2002-03-13 02:58:39 +08:00
|
|
|
#include <byteswap.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
|
|
|
|
2009-01-12 18:13:27 +08:00
|
|
|
#ifndef SOL_BLUETOOTH
|
|
|
|
#define SOL_BLUETOOTH 274
|
|
|
|
#endif
|
|
|
|
|
2009-01-15 06:31:44 +08:00
|
|
|
#define BT_SECURITY 4
|
2009-01-12 18:13:27 +08:00
|
|
|
struct bt_security {
|
|
|
|
uint8_t level;
|
|
|
|
};
|
|
|
|
#define BT_SECURITY_SDP 0
|
|
|
|
#define BT_SECURITY_LOW 1
|
|
|
|
#define BT_SECURITY_MEDIUM 2
|
|
|
|
#define BT_SECURITY_HIGH 3
|
|
|
|
|
2009-01-15 06:31:44 +08:00
|
|
|
#define BT_DEFER_SETUP 7
|
2009-01-12 18:13:27 +08:00
|
|
|
|
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);
|
2005-03-27 22:43:44 +08:00
|
|
|
int ba2oui(const bdaddr_t *ba, char *oui);
|
2007-06-22 05:18:00 +08:00
|
|
|
int bachk(const char *str);
|
2002-03-09 05:10:06 +08:00
|
|
|
|
2005-03-27 22:37:59 +08:00
|
|
|
int baprintf(const char *format, ...);
|
|
|
|
int bafprintf(FILE *stream, const char *format, ...);
|
|
|
|
int basprintf(char *str, const char *format, ...);
|
|
|
|
int basnprintf(char *str, size_t size, const char *format, ...);
|
|
|
|
|
2005-08-05 15:11:32 +08:00
|
|
|
void *bt_malloc(size_t size);
|
|
|
|
void bt_free(void *ptr);
|
|
|
|
|
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 */
|