bluez/android/hal-utils.h
Tedd Ho-Jeong An 44b4662529 android: Add SPDX License Identifier
This patch adds SPDX License Identifier and removes the license text.

-------------------------------------
       License            COUNT
-------------------------------------
 Apache-2.0           :     80
 LGPL-2.1-or-later    :     42
 GPL-2.0-or-later     :      9

License: Apache-2.0
   android/bluetoothd-wrapper.c
   android/tester-hidhost.c
   android/tester-map-client.c
   android/hal-audio-aptx.c
   android/hal-audio.c
   android/hal-handsfree-client.c
   android/tester-gatt.c
   android/hal-pan.c
   android/hal-socket.c
   android/tester-hdp.c
   android/tester-pan.c
   android/tester-avrcp.c
   android/hal-a2dp-sink.c
   android/hal-gatt.c
   android/hal-avrcp.c
   android/tester-a2dp.c
   android/hal-audio.h
   android/hal-bluetooth.c
   android/tester-socket.c
   android/hal-health.c
   android/hal-a2dp.c
   android/hal-ipc.c
   android/hal-avrcp-ctrl.c
   android/hal-sco.c
   android/hal-ipc.h
   android/tester-main.c
   android/hal-audio-sbc.c
   android/hal-utils.c
   android/hal-map-client.c
   android/hal-handsfree.c
   android/hal-log.h
   android/hal.h
   android/hal-utils.h
   android/tester-bluetooth.c
   android/hal-hidhost.c
   android/audio_utils/resampler.h
   android/audio_utils/resampler.c
   android/system/audio.h
   android/hardware/bt_sock.h
   android/hardware/bt_gatt_client.h
   android/hardware/bt_hh.h
   android/hardware/bluetooth.h
   android/hardware/hardware.h
   android/hardware/bt_hf_client.h
   android/hardware/bt_rc.h
   android/hardware/bt_hf.h
   android/hardware/bt_pan.h
   android/hardware/bt_gatt_types.h
   android/hardware/hardware.c
   android/hardware/audio_effect.h
   android/hardware/audio.h
   android/hardware/bt_gatt_server.h
   android/hardware/bt_gatt.h
   android/hardware/bt_hl.h
   android/hardware/bt_mce.h
   android/hardware/bt_av.h
   android/client/if-hh.c
   android/client/if-sco.c
   android/client/pollhandler.h
   android/client/haltest.c
   android/client/tabcompletion.c
   android/client/if-hf-client.c
   android/client/history.h
   android/client/if-audio.c
   android/client/terminal.h
   android/client/if-av.c
   android/client/if-main.h
   android/client/if-av-sink.c
   android/client/terminal.c
   android/client/if-mce.c
   android/client/if-hf.c
   android/client/pollhandler.c
   android/client/if-sock.c
   android/client/if-rc-ctrl.c
   android/client/if-rc.c
   android/client/history.c
   android/client/if-pan.c
   android/client/if-gatt.c
   android/client/if-bt.c
   android/client/if-hl.c

License: LGPL-2.1-or-later
   android/sco.h
   android/socket.c
   android/tester-main.h
   android/hidhost.h
   android/map-client.h
   android/utils.h
   android/hal-msg.h
   android/health.h
   android/avrcp-lib.c
   android/bluetoothd-snoop.c
   android/a2dp.c
   android/bluetooth.h
   android/a2dp-sink.c
   android/handsfree-client.c
   android/audio-msg.h
   android/main.c
   android/pan.c
   android/ipc-tester.c
   android/health.c
   android/socket.h
   android/handsfree.h
   android/avrcp-lib.h
   android/a2dp-sink.h
   android/system-emulator.c
   android/gatt.c
   android/avrcp.h
   android/pan.h
   android/test-ipc.c
   android/hidhost.c
   android/a2dp.h
   android/avrcp.c
   android/sco-msg.h
   android/bluetooth.c
   android/map-client.c
   android/handsfree-client.h
   android/ipc.c
   android/handsfree.c
   android/gatt.h
   android/ipc.h
   android/ipc-common.h
   android/compat/wordexp.h
   android/cutils/properties.h

License: GPL-2.0-or-later
   android/avdtp.h
   android/avctp.c
   android/avdtptest.c
   android/sco.c
   android/log.c
   android/avdtp.c
   android/avctp.h
   android/compat/readline/history.h
   android/compat/readline/readline.h
2020-09-21 16:19:33 -07:00

142 lines
4.1 KiB
C

/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2013 Intel Corporation
*
*/
#include <endian.h>
#include <hardware/bluetooth.h>
#define MAX_UUID_STR_LEN 37
#define HAL_UUID_LEN 16
#define MAX_ADDR_STR_LEN 18
static const char BT_BASE_UUID[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
};
const char *bt_uuid_t2str(const uint8_t *uuid, char *buf);
const char *btuuid2str(const uint8_t *uuid);
const char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf);
void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
const char *btproperty2str(const bt_property_t *property);
const char *bdaddr2str(const bt_bdaddr_t *bd_addr);
int get_config(const char *config_key, char *value, const char *fallback);
/*
* Begin mapping section
*
* There are some mappings between integer values (enums) and strings
* to be presented to user. To make it easier to convert between those two
* set of macros is given. It is specially useful when we want to have
* strings that match constants from header files like:
* BT_STATUS_SUCCESS (0) and corresponding "BT_STATUS_SUCCESS"
* Example of usage:
*
* INTMAP(int, -1, "invalid")
* DELEMENT(BT_STATUS_SUCCESS)
* DELEMENT(BT_STATUS_FAIL)
* MELEMENT(123, "Some strange value")
* ENDMAP
*
* Just by doing this we have mapping table plus two functions:
* int str2int(const char *str);
* const char *int2str(int v);
*
* second argument to INTMAP specifies value to be returned from
* str2int function when there is not mapping for such number
* third argument specifies default value to be returned from int2str
*
* If same mapping is to be used in several source files put
* INTMAP in c file and DECINTMAP in h file.
*
* For mappings that are to be used in single file only
* use SINTMAP which will create the same but everything will be marked
* as static.
*/
struct int2str {
int val; /* int value */
const char *str; /* corresponding string */
};
int int2str_findint(int v, const struct int2str m[]);
int int2str_findstr(const char *str, const struct int2str m[]);
const char *enum_defines(void *v, int i);
const char *enum_strings(void *v, int i);
const char *enum_one_string(void *v, int i);
#define TYPE_ENUM(type) ((void *) &__##type##2str[0])
#define DECINTMAP(type) \
extern struct int2str __##type##2str[]; \
const char *type##2##str(type v); \
type str##2##type(const char *str); \
#define INTMAP(type, deft, defs) \
const char *type##2##str(type v) \
{ \
int i = int2str_findint((int) v, __##type##2str); \
return (i < 0) ? defs : __##type##2str[i].str; \
} \
type str##2##type(const char *str) \
{ \
int i = int2str_findstr(str, __##type##2str); \
return (i < 0) ? (type) deft : (type) (__##type##2str[i].val); \
} \
struct int2str __##type##2str[] = {
#define SINTMAP(type, deft, defs) \
static struct int2str __##type##2str[]; \
static inline const char *type##2##str(type v) \
{ \
int i = int2str_findint((int) v, __##type##2str); \
return (i < 0) ? defs : __##type##2str[i].str; \
} \
static inline type str##2##type(const char *str) \
{ \
int i = int2str_findstr(str, __##type##2str); \
return (i < 0) ? (type) deft : (type) (__##type##2str[i].val); \
} \
static struct int2str __##type##2str[] = {
#define ENDMAP {0, NULL} };
/* use this to generate string from header file constant */
#define MELEMENT(v, s) {v, s}
/* use this to have arbitrary mapping from int to string */
#define DELEMENT(s) {s, #s}
/* End of mapping section */
DECINTMAP(bt_status_t);
DECINTMAP(bt_state_t);
DECINTMAP(bt_device_type_t);
DECINTMAP(bt_scan_mode_t);
DECINTMAP(bt_discovery_state_t);
DECINTMAP(bt_acl_state_t);
DECINTMAP(bt_bond_state_t);
DECINTMAP(bt_ssp_variant_t);
DECINTMAP(bt_property_type_t);
DECINTMAP(bt_cb_thread_evt);
static inline uint16_t get_le16(const void *src)
{
const struct __attribute__((packed)) {
uint16_t le16;
} *p = src;
return le16toh(p->le16);
}
static inline void put_le16(uint16_t val, void *dst)
{
struct __attribute__((packed)) {
uint16_t le16;
} *p = dst;
p->le16 = htole16(val);
}