1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2013 Intel Corporation
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/un.h>
#include <poll.h>
#include <hardware/audio.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_av.h>
#include <hardware/bt_hh.h>
#include <hardware/bt_pan.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_hf.h>
#include <hardware/bt_hl.h>
#include "hal.h"
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
#include <hardware/bt_hf_client.h>
#include <hardware/bt_mce.h>
#endif
#include <hardware/bt_rc.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>
#include <hardware/bt_gatt_client.h>
#include <hardware/bt_gatt_server.h>
extern audio_hw_device_t *if_audio;
/* Interfaces from hal that can be populated during application lifetime */
extern const bt_interface_t *if_bluetooth;
extern const btav_interface_t *if_av;
extern const btrc_interface_t *if_rc;
extern const bthf_interface_t *if_hf;
extern const bthh_interface_t *if_hh;
extern const btpan_interface_t *if_pan;
extern const bthl_interface_t *if_hl;
extern const btsock_interface_t *if_sock;
extern const btgatt_interface_t *if_gatt;
extern const btgatt_server_interface_t *if_gatt_server;
extern const btgatt_client_interface_t *if_gatt_client;
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
extern const btrc_ctrl_interface_t *if_rc_ctrl;
extern const bthf_client_interface_t *if_hf_client;
extern const btmce_interface_t *if_mce;
extern const btav_interface_t *if_av_sink;
#endif
/*
* Structure defines top level interfaces that can be used in test tool
* this will contain values as: bluetooth, av, gatt, socket, pan...
*/
struct interface {
const char *name; /* interface name */
struct method *methods; /* methods available for this interface */
};
extern const struct interface audio_if;
extern const struct interface sco_if;
extern const struct interface bluetooth_if;
extern const struct interface av_if;
extern const struct interface rc_if;
extern const struct interface gatt_if;
extern const struct interface gatt_client_if;
extern const struct interface gatt_server_if;
extern const struct interface pan_if;
extern const struct interface sock_if;
extern const struct interface hf_if;
extern const struct interface hh_if;
extern const struct interface hl_if;
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
extern const struct interface ctrl_rc_if;
extern const struct interface hf_client_if;
extern const struct interface mce_if;
extern const struct interface av_sink_if;
#endif
/* Interfaces that will show up in tool (first part of command line) */
extern const struct interface *interfaces[];
#define METHOD(name, func, comp, help) {name, func, comp, help}
#define STD_METHOD(m) {#m, m##_p, NULL, NULL}
#define STD_METHODC(m) {#m, m##_p, m##_c, NULL}
#define STD_METHODH(m, h) {#m, m##_p, NULL, h}
#define STD_METHODCH(m, h) {#m, m##_p, m##_c, h}
#define END_METHOD {"", NULL, NULL, NULL}
/*
* Function to parse argument for function, argv[0] and argv[1] are already
* parsed before this function is called and contain interface and method name
* up to argc - 1 arguments are finished and should be used to decide which
* function enumeration function to return
*/
typedef void (*parse_and_call)(int argc, const char **argv);
/*
* This is prototype of function that will return string for given number.
* Purpose is to enumerate string for auto completion.
* Function of this type will always be called in loop.
* First time function is called i = 0, then if function returns non-NULL
* it will be called again till for some value of i it will return NULL
*/
typedef const char *(*enum_func)(void *user, int i);
/*
* This is prototype of function that when given argc, argv will
* fill enum_func with pointer to function that will enumerate
* parameters for argc argument, user will be passed to enum_func.
*/
typedef void (*tab_complete)(int argc, const char **argv, enum_func *enum_func,
void **user);
/*
* For each method there is name and two functions to parse command line
* and call proper hal function on.
*/
struct method {
const char *name;
parse_and_call func;
tab_complete complete;
const char *help;
};
int haltest_error(const char *format, ...)
__attribute__((format(printf, 1, 2)));
int haltest_info(const char *format, ...)__attribute__((format(printf, 1, 2)));
int haltest_warn(const char *format, ...)__attribute__((format(printf, 1, 2)));
/* Enumerator for discovered devices, to be used as tab completion enum_func */
const char *enum_devices(void *v, int i);
const char *interface_name(void *v, int i);
const char *command_name(void *v, int i);
void add_remote_device(const bt_bdaddr_t *addr);
bool close_hw_bt_dev(void);
const struct interface *get_interface(const char *name);
struct method *get_method(struct method *methods, const char *name);
struct method *get_command(const char *name);
const struct method *get_interface_method(const char *iname,
const char *mname);
#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
/* Helper macro for executing function on interface and printing BT_STATUS */
#define EXEC(f, ...) \
{ \
if (f) { \
int err = f(__VA_ARGS__); \
haltest_info("%s: %s\n", #f, bt_status_t2str(err)); \
} else { \
haltest_info("%s is NULL\n", #f); \
} \
}
/* Helper macro for executing void function on interface */
#define EXECV(f, ...) \
{ \
(void) f(__VA_ARGS__); \
haltest_info("%s: void\n", #f); \
}
#define RETURN_IF_NULL(x) \
do { if (!x) { haltest_error("%s is NULL\n", #x); return; } } while (0)
#define VERIFY_ADDR_ARG(n, adr) \
do { \
if (n < argc) {\
str2bt_bdaddr_t(argv[n], adr); \
} else { \
haltest_error("No address specified\n");\
return;\
} \
} while (0)
|