ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
bluetooth.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <endian.h>
#include <byteswap.h>
#include <netinet/in.h>

Go to the source code of this file.

Data Structures

struct  bt_security
 
struct  bt_power
 
struct  bt_voice
 
struct  __attribute__
 
struct  uint128_t
 

Macros

#define AF_BLUETOOTH   31
 
#define PF_BLUETOOTH   AF_BLUETOOTH
 
#define BTPROTO_L2CAP   0
 
#define BTPROTO_HCI   1
 
#define BTPROTO_SCO   2
 
#define BTPROTO_RFCOMM   3
 
#define BTPROTO_BNEP   4
 
#define BTPROTO_CMTP   5
 
#define BTPROTO_HIDP   6
 
#define BTPROTO_AVDTP   7
 
#define SOL_HCI   0
 
#define SOL_L2CAP   6
 
#define SOL_SCO   17
 
#define SOL_RFCOMM   18
 
#define SOL_BLUETOOTH   274
 
#define BT_SECURITY   4
 
#define BT_SECURITY_SDP   0
 
#define BT_SECURITY_LOW   1
 
#define BT_SECURITY_MEDIUM   2
 
#define BT_SECURITY_HIGH   3
 
#define BT_DEFER_SETUP   7
 
#define BT_FLUSHABLE   8
 
#define BT_FLUSHABLE_OFF   0
 
#define BT_FLUSHABLE_ON   1
 
#define BT_POWER   9
 
#define BT_POWER_FORCE_ACTIVE_OFF   0
 
#define BT_POWER_FORCE_ACTIVE_ON   1
 
#define BT_CHANNEL_POLICY   10
 
#define BT_CHANNEL_POLICY_BREDR_ONLY   0
 
#define BT_CHANNEL_POLICY_BREDR_PREFERRED   1
 
#define BT_CHANNEL_POLICY_AMP_PREFERRED   2
 
#define BT_VOICE   11
 
#define BT_SNDMTU   12
 
#define BT_RCVMTU   13
 
#define BT_VOICE_TRANSPARENT   0x0003
 
#define BT_VOICE_CVSD_16BIT   0x0060
 
#define htobs(d)   (d)
 
#define htobl(d)   (d)
 
#define htobll(d)   (d)
 
#define btohs(d)   (d)
 
#define btohl(d)   (d)
 
#define btohll(d)   (d)
 
#define bt_get_unaligned(ptr)
 
#define bt_put_unaligned(val, ptr)
 
#define BDADDR_BREDR   0x00
 
#define BDADDR_LE_PUBLIC   0x01
 
#define BDADDR_LE_RANDOM   0x02
 
#define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
 
#define BDADDR_ALL   (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
 
#define BDADDR_LOCAL   (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
 
#define ntoh64(x)   (x)
 
#define hton64(x)   ntoh64(x)
 
#define hton128(x, y)   ntoh128(x, y)
 
#define htob128(x, y)   btoh128(x, y)
 

Enumerations

enum  {
  BT_CONNECTED = 1, BT_OPEN, BT_BOUND, BT_LISTEN,
  BT_CONNECT, BT_CONNECT2, BT_CONFIG, BT_DISCONN,
  BT_CLOSED
}
 

Functions

static uint64_t bt_get_le64 (const void *ptr)
 
static uint64_t bt_get_be64 (const void *ptr)
 
static uint32_t bt_get_le32 (const void *ptr)
 
static uint32_t bt_get_be32 (const void *ptr)
 
static uint16_t bt_get_le16 (const void *ptr)
 
static uint16_t bt_get_be16 (const void *ptr)
 
static void bt_put_le64 (uint64_t val, const void *ptr)
 
static void bt_put_be64 (uint64_t val, const void *ptr)
 
static void bt_put_le32 (uint32_t val, const void *ptr)
 
static void bt_put_be32 (uint32_t val, const void *ptr)
 
static void bt_put_le16 (uint16_t val, const void *ptr)
 
static void bt_put_be16 (uint16_t val, const void *ptr)
 
static int bacmp (const bdaddr_t *ba1, const bdaddr_t *ba2)
 
static void bacpy (bdaddr_t *dst, const bdaddr_t *src)
 
void baswap (bdaddr_t *dst, const bdaddr_t *src)
 
bdaddr_t * strtoba (const char *str)
 
char * batostr (const bdaddr_t *ba)
 
int ba2str (const bdaddr_t *ba, char *str)
 
int str2ba (const char *str, bdaddr_t *ba)
 
int ba2oui (const bdaddr_t *ba, char *oui)
 
int bachk (const char *str)
 
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,...)
 
void * bt_malloc (size_t size)
 
void bt_free (void *ptr)
 
int bt_error (uint16_t code)
 
const char * bt_compidtostr (int id)
 
static void bswap_128 (const void *src, void *dst)
 
static void ntoh128 (const uint128_t *src, uint128_t *dst)
 
static void btoh128 (const uint128_t *src, uint128_t *dst)
 

Macro Definition Documentation

#define AF_BLUETOOTH   31
#define BDADDR_ALL   (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})

Definition at line 310 of file bluetooth.h.

#define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})

Definition at line 309 of file bluetooth.h.

Referenced by hci_get_route(), and main().

#define BDADDR_BREDR   0x00

Definition at line 305 of file bluetooth.h.

#define BDADDR_LE_PUBLIC   0x01

Definition at line 306 of file bluetooth.h.

Referenced by main().

#define BDADDR_LE_RANDOM   0x02

Definition at line 307 of file bluetooth.h.

Referenced by main().

#define BDADDR_LOCAL   (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})

Definition at line 311 of file bluetooth.h.

#define BT_CHANNEL_POLICY   10

Definition at line 87 of file bluetooth.h.

#define BT_CHANNEL_POLICY_AMP_PREFERRED   2

Definition at line 112 of file bluetooth.h.

#define BT_CHANNEL_POLICY_BREDR_ONLY   0

Definition at line 94 of file bluetooth.h.

#define BT_CHANNEL_POLICY_BREDR_PREFERRED   1

Definition at line 101 of file bluetooth.h.

#define BT_DEFER_SETUP   7

Definition at line 73 of file bluetooth.h.

#define BT_FLUSHABLE   8

Definition at line 75 of file bluetooth.h.

#define BT_FLUSHABLE_OFF   0

Definition at line 77 of file bluetooth.h.

#define BT_FLUSHABLE_ON   1

Definition at line 78 of file bluetooth.h.

#define bt_get_unaligned (   ptr)
Value:
__extension__ ({ \
struct __attribute__((packed)) { \
__typeof__(*(ptr)) __v; \
} *__p = (__typeof__(__p)) (ptr); \
__p->__v; \
})

Definition at line 158 of file bluetooth.h.

Referenced by bt_get_be16(), bt_get_be32(), bt_get_be64(), bt_get_le16(), bt_get_le32(), and bt_get_le64().

#define BT_POWER   9

Definition at line 80 of file bluetooth.h.

#define BT_POWER_FORCE_ACTIVE_OFF   0

Definition at line 84 of file bluetooth.h.

#define BT_POWER_FORCE_ACTIVE_ON   1

Definition at line 85 of file bluetooth.h.

#define bt_put_unaligned (   val,
  ptr 
)
Value:
do { \
struct __attribute__((packed)) { \
__typeof__(*(ptr)) __v; \
} *__p = (__typeof__(__p)) (ptr); \
__p->__v = (val); \
} while(0)

Definition at line 166 of file bluetooth.h.

Referenced by bt_put_be16(), bt_put_be32(), bt_put_be64(), bt_put_le16(), bt_put_le32(), and bt_put_le64().

#define BT_RCVMTU   13

Definition at line 120 of file bluetooth.h.

#define BT_SECURITY   4

Definition at line 63 of file bluetooth.h.

Referenced by bt_att_get_security(), bt_att_set_security(), and l2cap_le_att_connect().

#define BT_SECURITY_HIGH   3

Definition at line 71 of file bluetooth.h.

Referenced by main().

#define BT_SECURITY_LOW   1

Definition at line 69 of file bluetooth.h.

Referenced by bt_att_new(), bt_gatt_client_write_without_response(), and main().

#define BT_SECURITY_MEDIUM   2

Definition at line 70 of file bluetooth.h.

Referenced by main().

#define BT_SECURITY_SDP   0

Definition at line 68 of file bluetooth.h.

#define BT_SNDMTU   12

Definition at line 119 of file bluetooth.h.

#define BT_VOICE   11

Definition at line 114 of file bluetooth.h.

#define BT_VOICE_CVSD_16BIT   0x0060

Definition at line 123 of file bluetooth.h.

#define BT_VOICE_TRANSPARENT   0x0003

Definition at line 122 of file bluetooth.h.

#define btohl (   d)    (d)

Definition at line 144 of file bluetooth.h.

#define btohll (   d)    (d)

Definition at line 145 of file bluetooth.h.

#define btohs (   d)    (d)

Definition at line 143 of file bluetooth.h.

Referenced by hci_read_local_version(), and hci_read_remote_version().

#define BTPROTO_AVDTP   7

Definition at line 52 of file bluetooth.h.

#define BTPROTO_BNEP   4

Definition at line 49 of file bluetooth.h.

#define BTPROTO_CMTP   5

Definition at line 50 of file bluetooth.h.

#define BTPROTO_HCI   1

Definition at line 46 of file bluetooth.h.

Referenced by hci_devinfo(), hci_for_each_dev(), hci_inquiry(), and hci_open_dev().

#define BTPROTO_HIDP   6

Definition at line 51 of file bluetooth.h.

#define BTPROTO_L2CAP   0

Definition at line 45 of file bluetooth.h.

Referenced by is_io_l2cap_based(), and l2cap_le_att_connect().

#define BTPROTO_RFCOMM   3

Definition at line 48 of file bluetooth.h.

#define BTPROTO_SCO   2

Definition at line 47 of file bluetooth.h.

#define htob128 (   x,
 
)    btoh128(x, y)

Definition at line 397 of file bluetooth.h.

#define htobl (   d)    (d)

Definition at line 141 of file bluetooth.h.

#define htobll (   d)    (d)

Definition at line 142 of file bluetooth.h.

#define htobs (   d)    (d)

Definition at line 140 of file bluetooth.h.

Referenced by hci_le_conn_update(), hci_send_cmd(), hci_send_req(), and l2cap_le_att_connect().

#define hton128 (   x,
 
)    ntoh128(x, y)

Definition at line 396 of file bluetooth.h.

#define hton64 (   x)    ntoh64(x)

Definition at line 395 of file bluetooth.h.

#define ntoh64 (   x)    (x)

Definition at line 358 of file bluetooth.h.

#define PF_BLUETOOTH   AF_BLUETOOTH

Definition at line 42 of file bluetooth.h.

Referenced by l2cap_le_att_connect().

#define SOL_BLUETOOTH   274

Definition at line 60 of file bluetooth.h.

Referenced by bt_att_get_security(), bt_att_set_security(), and l2cap_le_att_connect().

#define SOL_HCI   0

Definition at line 54 of file bluetooth.h.

Referenced by hci_send_req().

#define SOL_L2CAP   6

Definition at line 55 of file bluetooth.h.

#define SOL_RFCOMM   18

Definition at line 57 of file bluetooth.h.

#define SOL_SCO   17

Definition at line 56 of file bluetooth.h.

Enumeration Type Documentation

anonymous enum
Enumerator
BT_CONNECTED 
BT_OPEN 
BT_BOUND 
BT_LISTEN 
BT_CONNECT 
BT_CONNECT2 
BT_CONFIG 
BT_DISCONN 
BT_CLOSED 

Definition at line 126 of file bluetooth.h.

Function Documentation

int ba2oui ( const bdaddr_t *  ba,
char *  oui 
)

Definition at line 107 of file bluetooth.c.

int ba2str ( const bdaddr_t *  ba,
char *  str 
)

Definition at line 86 of file bluetooth.c.

Referenced by l2cap_le_att_connect().

int bachk ( const char *  str)

Definition at line 112 of file bluetooth.c.

Referenced by str2ba().

static int bacmp ( const bdaddr_t *  ba1,
const bdaddr_t *  ba2 
)
inlinestatic

Definition at line 314 of file bluetooth.h.

Referenced by __other_bdaddr(), __same_bdaddr(), and hci_send_req().

int bafprintf ( FILE *  stream,
const char *  format,
  ... 
)

Definition at line 149 of file bluetooth.c.

int baprintf ( const char *  format,
  ... 
)

Definition at line 137 of file bluetooth.c.

int basnprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

Definition at line 173 of file bluetooth.c.

int basprintf ( char *  str,
const char *  format,
  ... 
)

Definition at line 161 of file bluetooth.c.

void baswap ( bdaddr_t *  dst,
const bdaddr_t *  src 
)

Definition at line 50 of file bluetooth.c.

Referenced by strtoba().

char* batostr ( const bdaddr_t *  ba)

Definition at line 60 of file bluetooth.c.

References bt_malloc().

static void bswap_128 ( const void *  src,
void *  dst 
)
inlinestatic
const char* bt_compidtostr ( int  id)

Definition at line 270 of file bluetooth.c.

void bt_free ( void *  ptr)

Definition at line 190 of file bluetooth.c.

Referenced by hci_lmtostr().

static uint16_t bt_get_be16 ( const void *  ptr)
inlinestatic

Definition at line 200 of file bluetooth.h.

References bt_get_unaligned.

static uint32_t bt_get_be32 ( const void *  ptr)
inlinestatic

Definition at line 190 of file bluetooth.h.

References bt_get_unaligned.

static uint64_t bt_get_be64 ( const void *  ptr)
inlinestatic

Definition at line 180 of file bluetooth.h.

References bt_get_unaligned.

static uint16_t bt_get_le16 ( const void *  ptr)
inlinestatic

Definition at line 195 of file bluetooth.h.

References bt_get_unaligned.

static uint32_t bt_get_le32 ( const void *  ptr)
inlinestatic

Definition at line 185 of file bluetooth.h.

References bt_get_unaligned.

static uint64_t bt_get_le64 ( const void *  ptr)
inlinestatic

Definition at line 175 of file bluetooth.h.

References bt_get_unaligned.

void* bt_malloc ( size_t  size)
static void bt_put_be16 ( uint16_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 230 of file bluetooth.h.

References bt_put_unaligned.

static void bt_put_be32 ( uint32_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 220 of file bluetooth.h.

References bt_put_unaligned.

static void bt_put_be64 ( uint64_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 210 of file bluetooth.h.

References bt_put_unaligned.

static void bt_put_le16 ( uint16_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 225 of file bluetooth.h.

References bt_put_unaligned.

Referenced by bt_uuid_to_le().

static void bt_put_le32 ( uint32_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 215 of file bluetooth.h.

References bt_put_unaligned.

static void bt_put_le64 ( uint64_t  val,
const void *  ptr 
)
inlinestatic

Definition at line 205 of file bluetooth.h.

References bt_put_unaligned.

static void btoh128 ( const uint128_t src,
uint128_t dst 
)
inlinestatic

Definition at line 365 of file bluetooth.h.

References bswap_128().

static void ntoh128 ( const uint128_t src,
uint128_t dst 
)
inlinestatic

Definition at line 360 of file bluetooth.h.

int str2ba ( const char *  str,
bdaddr_t *  ba 
)

Definition at line 92 of file bluetooth.c.

References bachk().

Referenced by hci_devid(), main(), and strtoba().

bdaddr_t* strtoba ( const char *  str)

Definition at line 73 of file bluetooth.c.

References baswap(), bt_malloc(), and str2ba().