Commit b79a3415 authored by Mariusz Skamra's avatar Mariusz Skamra Committed by Carles Cufi
Browse files

Bluetooth: audio: has_client: Move bt_has_client structure to header



This moves bt_has_client instance structure to has_internal.h header
file to be able to access to the instance members in tests.

Signed-off-by: default avatarMariusz Skamra <mariusz.skamra@codecoup.pl>
parent 47d3d9f4
Loading
Loading
Loading
Loading
+71 −96
Original line number Diff line number Diff line
@@ -19,48 +19,14 @@

LOG_MODULE_REGISTER(bt_has_client, CONFIG_BT_HAS_CLIENT_LOG_LEVEL);

#define HAS_INST(_has) CONTAINER_OF(_has, struct has_inst, has)
#define HAS_INST(_has) CONTAINER_OF(_has, struct bt_has_client, has)
#define HANDLE_IS_VALID(handle) ((handle) != 0x0000)

enum {
	HAS_DISCOVER_IN_PROGRESS,
	HAS_CP_OPERATION_IN_PROGRESS,

	HAS_NUM_FLAGS, /* keep as last */
};

static struct has_inst {
	/** Common profile reference object */
	struct bt_has has;

	/** Profile connection reference */
	struct bt_conn *conn;

	/** Internal flags */
	ATOMIC_DEFINE(flags, HAS_NUM_FLAGS);

	/* GATT procedure parameters */
	union {
		struct {
			struct bt_uuid_16 uuid;
			union {
				struct bt_gatt_read_params read;
				struct bt_gatt_discover_params discover;
			};
		};
		struct bt_gatt_write_params write;
	} params;

	struct bt_gatt_subscribe_params features_subscription;
	struct bt_gatt_subscribe_params control_point_subscription;
	struct bt_gatt_subscribe_params active_index_subscription;
} has_insts[CONFIG_BT_MAX_CONN];

static struct bt_has_client clients[CONFIG_BT_MAX_CONN];
static const struct bt_has_client_cb *client_cb;

static struct has_inst *inst_by_conn(struct bt_conn *conn)
static struct bt_has_client *inst_by_conn(struct bt_conn *conn)
{
	struct has_inst *inst = &has_insts[bt_conn_index(conn)];
	struct bt_has_client *inst = &clients[bt_conn_index(conn)];

	if (inst->conn == conn) {
		return inst;
@@ -69,14 +35,14 @@ static struct has_inst *inst_by_conn(struct bt_conn *conn)
	return NULL;
}

static void inst_cleanup(struct has_inst *inst)
static void inst_cleanup(struct bt_has_client *inst)
{
	bt_conn_unref(inst->conn);

	(void)memset(inst, 0, sizeof(*inst));
}

static enum bt_has_capabilities get_capabilities(const struct has_inst *inst)
static enum bt_has_capabilities get_capabilities(const struct bt_has_client *inst)
{
	enum bt_has_capabilities caps = 0;

@@ -88,7 +54,7 @@ static enum bt_has_capabilities get_capabilities(const struct has_inst *inst)
	return caps;
}

static void handle_read_preset_rsp(struct has_inst *inst, struct net_buf_simple *buf)
static void handle_read_preset_rsp(struct bt_has_client *inst, struct net_buf_simple *buf)
{
	const struct bt_has_cp_read_preset_rsp *pdu;
	struct bt_has_preset_record record;
@@ -124,7 +90,8 @@ static void handle_read_preset_rsp(struct has_inst *inst, struct net_buf_simple
	client_cb->preset_read_rsp(&inst->has, 0, &record, !!pdu->is_last);
}

static void handle_generic_update(struct has_inst *inst, struct net_buf_simple *buf, bool is_last)
static void handle_generic_update(struct bt_has_client *inst, struct net_buf_simple *buf,
				  bool is_last)
{
	const struct bt_has_cp_generic_update *pdu;
	struct bt_has_preset_record record;
@@ -154,7 +121,8 @@ static void handle_generic_update(struct has_inst *inst, struct net_buf_simple *
	client_cb->preset_update(&inst->has, pdu->prev_index, &record, is_last);
}

static void handle_preset_deleted(struct has_inst *inst, struct net_buf_simple *buf, bool is_last)
static void handle_preset_deleted(struct bt_has_client *inst, struct net_buf_simple *buf,
				  bool is_last)
{
	if (buf->len < sizeof(uint8_t)) {
		LOG_ERR("malformed PDU");
@@ -164,7 +132,7 @@ static void handle_preset_deleted(struct has_inst *inst, struct net_buf_simple *
	client_cb->preset_deleted(&inst->has, net_buf_simple_pull_u8(buf), is_last);
}

static void handle_preset_availability(struct has_inst *inst, struct net_buf_simple *buf,
static void handle_preset_availability(struct bt_has_client *inst, struct net_buf_simple *buf,
				       bool available, bool is_last)
{
	if (buf->len < sizeof(uint8_t)) {
@@ -176,7 +144,7 @@ static void handle_preset_availability(struct has_inst *inst, struct net_buf_sim
				       is_last);
}

static void handle_preset_changed(struct has_inst *inst, struct net_buf_simple *buf)
static void handle_preset_changed(struct bt_has_client *inst, struct net_buf_simple *buf)
{
	const struct bt_has_cp_preset_changed *pdu;

@@ -223,7 +191,8 @@ static uint8_t control_point_notify_cb(struct bt_conn *conn,
				       struct bt_gatt_subscribe_params *params, const void *data,
				       uint16_t len)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, control_point_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  control_point_subscription);
	const struct bt_has_cp_hdr *hdr;
	struct net_buf_simple buf;

@@ -259,11 +228,11 @@ static uint8_t control_point_notify_cb(struct bt_conn *conn,
	return BT_GATT_ITER_CONTINUE;
}

static void discover_complete(struct has_inst *inst)
static void discover_complete(struct bt_has_client *inst)
{
	LOG_DBG("conn %p", (void *)inst->conn);

	atomic_clear_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS);
	atomic_clear_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS);

	client_cb->discover(inst->conn, 0, &inst->has,
			    inst->has.features & BT_HAS_FEAT_HEARING_AID_TYPE_MASK,
@@ -283,7 +252,8 @@ static void discover_failed(struct bt_conn *conn, int err)
	client_cb->discover(conn, err, NULL, 0, 0);
}

static int cp_write(struct has_inst *inst, struct net_buf_simple *buf, bt_gatt_write_func_t func)
static int cp_write(struct bt_has_client *inst, struct net_buf_simple *buf,
		    bt_gatt_write_func_t func)
{
	const uint16_t value_handle = inst->control_point_subscription.value_handle;

@@ -303,18 +273,18 @@ static int cp_write(struct has_inst *inst, struct net_buf_simple *buf, bt_gatt_w
static void read_presets_req_cb(struct bt_conn *conn, uint8_t err,
				struct bt_gatt_write_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.write);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.write);

	LOG_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params);

	atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS);
	atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS);

	if (err) {
		client_cb->preset_read_rsp(&inst->has, err, NULL, true);
	}
}

static int read_presets_req(struct has_inst *inst, uint8_t start_index, uint8_t num_presets)
static int read_presets_req(struct bt_has_client *inst, uint8_t start_index, uint8_t num_presets)
{
	struct bt_has_cp_hdr *hdr;
	struct bt_has_cp_read_presets_req *req;
@@ -336,18 +306,18 @@ static int read_presets_req(struct has_inst *inst, uint8_t start_index, uint8_t
static void set_active_preset_cb(struct bt_conn *conn, uint8_t err,
				 struct bt_gatt_write_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.write);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.write);

	LOG_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params);

	atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS);
	atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS);

	if (err) {
		client_cb->preset_switch(&inst->has, err, inst->has.active_index);
	}
}

static int preset_set(struct has_inst *inst, uint8_t opcode, uint8_t index)
static int preset_set(struct bt_has_client *inst, uint8_t opcode, uint8_t index)
{
	struct bt_has_cp_hdr *hdr;
	struct bt_has_cp_set_active_preset *req;
@@ -364,7 +334,7 @@ static int preset_set(struct has_inst *inst, uint8_t opcode, uint8_t index)
	return cp_write(inst, &buf, set_active_preset_cb);
}

static int preset_set_next_or_prev(struct has_inst *inst, uint8_t opcode)
static int preset_set_next_or_prev(struct bt_has_client *inst, uint8_t opcode)
{
	struct bt_has_cp_hdr *hdr;

@@ -378,7 +348,7 @@ static int preset_set_next_or_prev(struct has_inst *inst, uint8_t opcode)
	return cp_write(inst, &buf, set_active_preset_cb);
}

static uint8_t active_index_update(struct has_inst *inst, const void *data, uint16_t len)
static uint8_t active_index_update(struct bt_has_client *inst, const void *data, uint16_t len)
{
	struct net_buf_simple buf;
	const uint8_t prev = inst->has.active_index;
@@ -396,7 +366,8 @@ static uint8_t active_preset_notify_cb(struct bt_conn *conn,
				       struct bt_gatt_subscribe_params *params, const void *data,
				       uint16_t len)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, active_index_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  active_index_subscription);
	uint8_t prev;

	LOG_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len);
@@ -420,7 +391,7 @@ static uint8_t active_preset_notify_cb(struct bt_conn *conn,

	prev = active_index_update(inst, data, len);

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) {
		/* Got notification during discovery process, postpone the active_index callback
		 * until discovery is complete.
		 */
@@ -437,7 +408,8 @@ static uint8_t active_preset_notify_cb(struct bt_conn *conn,
static void active_index_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
				      struct bt_gatt_subscribe_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, active_index_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  active_index_subscription);

	LOG_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params);

@@ -451,7 +423,7 @@ static void active_index_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
	}
}

static int active_index_subscribe(struct has_inst *inst, uint16_t value_handle)
static int active_index_subscribe(struct bt_has_client *inst, uint16_t value_handle)
{
	LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);

@@ -471,7 +443,7 @@ static uint8_t active_index_read_cb(struct bt_conn *conn, uint8_t att_err,
				    struct bt_gatt_read_params *params, const void *data,
				    uint16_t len)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.read);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.read);
	int err = att_err;

	LOG_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params,
@@ -500,7 +472,7 @@ fail:
	return BT_GATT_ITER_STOP;
}

static int active_index_read(struct has_inst *inst)
static int active_index_read(struct bt_has_client *inst)
{
	LOG_DBG("conn %p", (void *)inst->conn);

@@ -520,7 +492,8 @@ static int active_index_read(struct has_inst *inst)
static void control_point_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
				       struct bt_gatt_subscribe_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, control_point_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  control_point_subscription);
	int err = att_err;

	LOG_DBG("conn %p att_err 0x%02x", (void *)inst->conn, att_err);
@@ -544,7 +517,7 @@ fail:
	discover_failed(conn, err);
}

static int control_point_subscribe(struct has_inst *inst, uint16_t value_handle,
static int control_point_subscribe(struct bt_has_client *inst, uint16_t value_handle,
				   uint8_t properties)
{
	LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);
@@ -569,7 +542,7 @@ static int control_point_subscribe(struct has_inst *inst, uint16_t value_handle,
static uint8_t control_point_discover_cb(struct bt_conn *conn, const struct bt_gatt_attr *attr,
					 struct bt_gatt_discover_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.discover);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.discover);
	const struct bt_gatt_chrc *chrc;
	int err;

@@ -596,7 +569,7 @@ static uint8_t control_point_discover_cb(struct bt_conn *conn, const struct bt_g
	return BT_GATT_ITER_STOP;
}

static int control_point_discover(struct has_inst *inst)
static int control_point_discover(struct bt_has_client *inst)
{
	LOG_DBG("conn %p", (void *)inst->conn);

@@ -613,7 +586,7 @@ static int control_point_discover(struct has_inst *inst)
	return bt_gatt_discover(inst->conn, &inst->params.discover);
}

static void features_update(struct has_inst *inst, const void *data, uint16_t len)
static void features_update(struct bt_has_client *inst, const void *data, uint16_t len)
{
	struct net_buf_simple buf;

@@ -627,7 +600,7 @@ static void features_update(struct has_inst *inst, const void *data, uint16_t le
static uint8_t features_read_cb(struct bt_conn *conn, uint8_t att_err,
				struct bt_gatt_read_params *params, const void *data, uint16_t len)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.read);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.read);
	int err = att_err;

	LOG_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params,
@@ -662,7 +635,7 @@ fail:
	return BT_GATT_ITER_STOP;
}

static int features_read(struct has_inst *inst, uint16_t value_handle)
static int features_read(struct bt_has_client *inst, uint16_t value_handle)
{
	LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);

@@ -679,7 +652,8 @@ static int features_read(struct has_inst *inst, uint16_t value_handle)
static void features_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
				  struct bt_gatt_subscribe_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, features_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  features_subscription);
	int err = att_err;

	LOG_DBG("conn %p att_err 0x%02x params %p", (void *)conn, att_err, params);
@@ -706,7 +680,8 @@ fail:
static uint8_t features_notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe_params *params,
				  const void *data, uint16_t len)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, features_subscription);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client,
						  features_subscription);

	LOG_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len);

@@ -732,7 +707,7 @@ static uint8_t features_notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe
	return BT_GATT_ITER_CONTINUE;
}

static int features_subscribe(struct has_inst *inst, uint16_t value_handle)
static int features_subscribe(struct bt_has_client *inst, uint16_t value_handle)
{
	LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);

@@ -751,7 +726,7 @@ static int features_subscribe(struct has_inst *inst, uint16_t value_handle)
static uint8_t features_discover_cb(struct bt_conn *conn, const struct bt_gatt_attr *attr,
				    struct bt_gatt_discover_params *params)
{
	struct has_inst *inst = CONTAINER_OF(params, struct has_inst, params.discover);
	struct bt_has_client *inst = CONTAINER_OF(params, struct bt_has_client, params.discover);
	const struct bt_gatt_chrc *chrc;
	int err;

@@ -790,7 +765,7 @@ fail:
	return BT_GATT_ITER_STOP;
}

static int features_discover(struct has_inst *inst)
static int features_discover(struct bt_has_client *inst)
{
	LOG_DBG("conn %p", (void *)inst->conn);

@@ -832,7 +807,7 @@ int bt_has_client_cb_register(const struct bt_has_client_cb *cb)
 */
int bt_has_client_discover(struct bt_conn *conn)
{
	struct has_inst *inst;
	struct bt_has_client *inst;
	int err;

	LOG_DBG("conn %p", (void *)conn);
@@ -841,10 +816,10 @@ int bt_has_client_discover(struct bt_conn *conn)
		return -EINVAL;
	}

	inst = &has_insts[bt_conn_index(conn)];
	inst = &clients[bt_conn_index(conn)];

	if (atomic_test_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) {
		return -EBUSY;
	}

@@ -856,7 +831,7 @@ int bt_has_client_discover(struct bt_conn *conn)

	err = features_discover(inst);
	if (err) {
		atomic_clear_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS);
		atomic_clear_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS);
	}

	return err;
@@ -864,7 +839,7 @@ int bt_has_client_discover(struct bt_conn *conn)

int bt_has_client_conn_get(const struct bt_has *has, struct bt_conn **conn)
{
	struct has_inst *inst = HAS_INST(has);
	struct bt_has_client *inst = HAS_INST(has);

	*conn = bt_conn_ref(inst->conn);

@@ -873,7 +848,7 @@ int bt_has_client_conn_get(const struct bt_has *has, struct bt_conn **conn)

int bt_has_client_presets_read(struct bt_has *has, uint8_t start_index, uint8_t count)
{
	struct has_inst *inst = HAS_INST(has);
	struct bt_has_client *inst = HAS_INST(has);
	int err;

	LOG_DBG("conn %p start_index 0x%02x count %d", (void *)inst->conn, start_index, count);
@@ -882,8 +857,8 @@ int bt_has_client_presets_read(struct bt_has *has, uint8_t start_index, uint8_t
		return -ENOTCONN;
	}

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) {
		return -EBUSY;
	}

@@ -897,7 +872,7 @@ int bt_has_client_presets_read(struct bt_has *has, uint8_t start_index, uint8_t

	err = read_presets_req(inst, start_index, count);
	if (err) {
		atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS);
		atomic_clear_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS);
	}

	return err;
@@ -905,7 +880,7 @@ int bt_has_client_presets_read(struct bt_has *has, uint8_t start_index, uint8_t

int bt_has_client_preset_set(struct bt_has *has, uint8_t index, bool sync)
{
	struct has_inst *inst = HAS_INST(has);
	struct bt_has_client *inst = HAS_INST(has);
	uint8_t opcode;

	LOG_DBG("conn %p index 0x%02x", (void *)inst->conn, index);
@@ -922,8 +897,8 @@ int bt_has_client_preset_set(struct bt_has *has, uint8_t index, bool sync)
		return -EOPNOTSUPP;
	}

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) {
		return -EBUSY;
	}

@@ -934,7 +909,7 @@ int bt_has_client_preset_set(struct bt_has *has, uint8_t index, bool sync)

int bt_has_client_preset_next(struct bt_has *has, bool sync)
{
	struct has_inst *inst = HAS_INST(has);
	struct bt_has_client *inst = HAS_INST(has);
	uint8_t opcode;

	LOG_DBG("conn %p sync %d", (void *)inst->conn, sync);
@@ -947,8 +922,8 @@ int bt_has_client_preset_next(struct bt_has *has, bool sync)
		return -EOPNOTSUPP;
	}

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) {
		return -EBUSY;
	}

@@ -959,7 +934,7 @@ int bt_has_client_preset_next(struct bt_has *has, bool sync)

int bt_has_client_preset_prev(struct bt_has *has, bool sync)
{
	struct has_inst *inst = HAS_INST(has);
	struct bt_has_client *inst = HAS_INST(has);
	uint8_t opcode;

	LOG_DBG("conn %p sync %d", (void *)inst->conn, sync);
@@ -972,8 +947,8 @@ int bt_has_client_preset_prev(struct bt_has *has, bool sync)
		return -EOPNOTSUPP;
	}

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS) ||
	    atomic_test_and_set_bit(inst->flags, HAS_CLIENT_CP_OPERATION_IN_PROGRESS)) {
		return -EBUSY;
	}

@@ -984,13 +959,13 @@ int bt_has_client_preset_prev(struct bt_has *has, bool sync)

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	struct has_inst *inst = inst_by_conn(conn);
	struct bt_has_client *inst = inst_by_conn(conn);

	if (!inst) {
		return;
	}

	if (atomic_test_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS)) {
	if (atomic_test_bit(inst->flags, HAS_CLIENT_DISCOVER_IN_PROGRESS)) {
		discover_failed(conn, -ECONNABORTED);
	}

+37 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>

/* Control Point opcodes */
#define BT_HAS_OP_READ_PRESET_REQ        0x01
#define BT_HAS_OP_READ_PRESET_RSP        0x02
@@ -139,3 +142,37 @@ static inline const char *bt_has_change_id_str(uint8_t change_id)
		return "Unknown changeId";
	}
}

enum has_client_flags {
	HAS_CLIENT_DISCOVER_IN_PROGRESS,
	HAS_CLIENT_CP_OPERATION_IN_PROGRESS,

	HAS_CLIENT_NUM_FLAGS, /* keep as last */
};

struct bt_has_client {
	/** Common profile reference object */
	struct bt_has has;

	/** Profile connection reference */
	struct bt_conn *conn;

	/** Internal flags */
	ATOMIC_DEFINE(flags, HAS_CLIENT_NUM_FLAGS);

	/* GATT procedure parameters */
	union {
		struct {
			struct bt_uuid_16 uuid;
			union {
				struct bt_gatt_read_params read;
				struct bt_gatt_discover_params discover;
			};
		};
		struct bt_gatt_write_params write;
	} params;

	struct bt_gatt_subscribe_params features_subscription;
	struct bt_gatt_subscribe_params control_point_subscription;
	struct bt_gatt_subscribe_params active_index_subscription;
};