ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
util.h File Reference
#include <stdint.h>
#include <stdlib.h>
#include <alloca.h>
#include <byteswap.h>
#include <string.h>

Go to the source code of this file.

Macros

#define le16_to_cpu(val)   (val)
 
#define le32_to_cpu(val)   (val)
 
#define le64_to_cpu(val)   (val)
 
#define cpu_to_le16(val)   (val)
 
#define cpu_to_le32(val)   (val)
 
#define cpu_to_le64(val)   (val)
 
#define be16_to_cpu(val)   bswap_16(val)
 
#define be32_to_cpu(val)   bswap_32(val)
 
#define be64_to_cpu(val)   bswap_64(val)
 
#define cpu_to_be16(val)   bswap_16(val)
 
#define cpu_to_be32(val)   bswap_32(val)
 
#define cpu_to_be64(val)   bswap_64(val)
 
#define get_unaligned(ptr)
 
#define put_unaligned(val, ptr)
 
#define PTR_TO_UINT(p)   ((unsigned int) ((uintptr_t) (p)))
 
#define UINT_TO_PTR(u)   ((void *) ((uintptr_t) (u)))
 
#define PTR_TO_INT(p)   ((int) ((intptr_t) (p)))
 
#define INT_TO_PTR(u)   ((void *) ((intptr_t) (u)))
 
#define new0(t, n)   ((t*) calloc((n), sizeof(t)))
 
#define newa(t, n)   ((t*) alloca(sizeof(t)*(n)))
 
#define malloc0(n)   (calloc((n), 1))
 

Typedefs

typedef void(* util_debug_func_t )(const char *str, void *user_data)
 

Functions

void util_debug (util_debug_func_t function, void *user_data, const char *format,...) __attribute__((format(printf
 
void void util_hexdump (const char dir, const unsigned char *buf, size_t len, util_debug_func_t function, void *user_data)
 
unsigned char util_get_dt (const char *parent, const char *name)
 
uint8_t util_get_uid (unsigned int *bitmap, uint8_t max)
 
void util_clear_uid (unsigned int *bitmap, uint8_t id)
 
static uint16_t get_le16 (const void *ptr)
 
static uint16_t get_be16 (const void *ptr)
 
static uint32_t get_le32 (const void *ptr)
 
static uint32_t get_be32 (const void *ptr)
 
static uint64_t get_le64 (const void *ptr)
 
static uint64_t get_be64 (const void *ptr)
 
static void put_le16 (uint16_t val, void *dst)
 
static void put_be16 (uint16_t val, const void *ptr)
 
static void put_le32 (uint32_t val, void *dst)
 
static void put_be32 (uint32_t val, void *dst)
 
static void put_le64 (uint64_t val, void *dst)
 
static void put_be64 (uint64_t val, void *dst)
 

Macro Definition Documentation

#define be16_to_cpu (   val)    bswap_16(val)

Definition at line 37 of file util.h.

Referenced by get_be16().

#define be32_to_cpu (   val)    bswap_32(val)

Definition at line 38 of file util.h.

Referenced by get_be32().

#define be64_to_cpu (   val)    bswap_64(val)

Definition at line 39 of file util.h.

Referenced by get_be64().

#define cpu_to_be16 (   val)    bswap_16(val)

Definition at line 40 of file util.h.

Referenced by put_be16().

#define cpu_to_be32 (   val)    bswap_32(val)

Definition at line 41 of file util.h.

Referenced by put_be32().

#define cpu_to_be64 (   val)    bswap_64(val)

Definition at line 42 of file util.h.

Referenced by put_be64().

#define cpu_to_le16 (   val)    (val)

Definition at line 34 of file util.h.

Referenced by put_le16().

#define cpu_to_le32 (   val)    (val)

Definition at line 35 of file util.h.

Referenced by put_le32().

#define cpu_to_le64 (   val)    (val)

Definition at line 36 of file util.h.

Referenced by put_le64().

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

Definition at line 60 of file util.h.

Referenced by get_be16(), get_be32(), get_be64(), get_le16(), get_le32(), and get_le64().

#define INT_TO_PTR (   u)    ((void *) ((intptr_t) (u)))

Definition at line 80 of file util.h.

Referenced by disconnect_cb().

#define le16_to_cpu (   val)    (val)

Definition at line 31 of file util.h.

Referenced by get_le16().

#define le32_to_cpu (   val)    (val)

Definition at line 32 of file util.h.

Referenced by get_le32().

#define le64_to_cpu (   val)    (val)

Definition at line 33 of file util.h.

Referenced by get_le64().

#define malloc0 (   n)    (calloc((n), 1))

Definition at line 84 of file util.h.

Referenced by new_attribute().

#define newa (   t,
 
)    ((t*) alloca(sizeof(t)*(n)))

Definition at line 83 of file util.h.

#define PTR_TO_INT (   p)    ((int) ((intptr_t) (p)))

Definition at line 79 of file util.h.

Referenced by disconn_handler().

#define PTR_TO_UINT (   p)    ((unsigned int) ((uintptr_t) (p)))
#define put_unaligned (   val,
  ptr 
)
Value:
do { \
struct __attribute__((packed)) { \
__typeof__(*(ptr)) __v; \
} *__p = (__typeof__(__p)) (ptr); \
__p->__v = (val); \
} while (0)

Definition at line 68 of file util.h.

Referenced by put_be16(), put_be32(), put_be64(), put_le16(), put_le32(), and put_le64().

Typedef Documentation

typedef void(* util_debug_func_t)(const char *str, void *user_data)

Definition at line 86 of file util.h.

Function Documentation

static uint16_t get_be16 ( const void *  ptr)
inlinestatic

Definition at line 105 of file util.h.

References be16_to_cpu, and get_unaligned.

static uint32_t get_be32 ( const void *  ptr)
inlinestatic

Definition at line 115 of file util.h.

References be32_to_cpu, and get_unaligned.

static uint64_t get_be64 ( const void *  ptr)
inlinestatic

Definition at line 125 of file util.h.

References be64_to_cpu, and get_unaligned.

static uint32_t get_le32 ( const void *  ptr)
inlinestatic

Definition at line 110 of file util.h.

References get_unaligned, and le32_to_cpu.

Referenced by bt_crypto_g2(), handle_signed(), and le_to_uuid().

static uint64_t get_le64 ( const void *  ptr)
inlinestatic

Definition at line 120 of file util.h.

References get_unaligned, and le64_to_cpu.

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

Definition at line 135 of file util.h.

References cpu_to_be16, and put_unaligned.

static void put_be32 ( uint32_t  val,
void *  dst 
)
inlinestatic

Definition at line 145 of file util.h.

References cpu_to_be32, and put_unaligned.

Referenced by bt_crypto_sign_att().

static void put_be64 ( uint64_t  val,
void *  dst 
)
inlinestatic

Definition at line 155 of file util.h.

References cpu_to_be64, and put_unaligned.

static void put_le32 ( uint32_t  val,
void *  dst 
)
inlinestatic

Definition at line 140 of file util.h.

References cpu_to_le32, and put_unaligned.

Referenced by bt_crypto_sign_att().

static void put_le64 ( uint64_t  val,
void *  dst 
)
inlinestatic

Definition at line 150 of file util.h.

References cpu_to_le64, and put_unaligned.

void util_clear_uid ( unsigned int *  bitmap,
uint8_t  id 
)

Clear id bit in bitmap

Parameters
bitmapmap of bits
idbit rank to clear

Definition at line 172 of file util.c.

void util_debug ( util_debug_func_t  function,
void *  user_data,
const char *  format,
  ... 
)
unsigned char util_get_dt ( const char *  parent,
const char *  name 
)

Helper for getting the dirent type in case readdir

Parameters
parentprefix to build full path
namesuffix to builld full path
Returns
DT_UNKNOWN or DT_DIR if parent/name is a DIR

Definition at line 130 of file util.c.

uint8_t util_get_uid ( unsigned int *  bitmap,
uint8_t  max 
)

Helpers for bitfield operations

Find unique id in range from 1 to max but no bigger then sizeof(int) * 8. ffs() is used since it is POSIX standard

Parameters
bitmapmap of bits
maxmax bit position
Returns

Definition at line 152 of file util.c.

void void util_hexdump ( const char  dir,
const unsigned char *  buf,
size_t  len,
util_debug_func_t  function,
void *  user_data 
)

hexadecimal dump utility: create the str hex string and then call function(str,user_data)

Parameters
dirfirst char of str
bufbuffer to convert to hex (str)
lensize of buffer (should be less than or equal to 16)
functionfunction to call with (str,user_data)
user_datapointer to pass to function

Definition at line 81 of file util.c.

References timeout_data::user_data.

Referenced by can_read_data(), and can_write_data().