2023-06-08 12:24:42

by Nitin Jadhav

[permalink] [raw]
Subject: [PATCH BlueZ v3 2/2] Make VOCS (Secondary) as an included service of VCS (Primary)

Fixed the following issue observed during PTS testing
- Specified Upper and Lower Limit for Volume offset
- Corrected the number of handles for VOCS
- VOCS is made as included service of VCS
(VOCS is secondary service and VSC is primary service)
---
v2: Cosmetic Changes (Bluez Test Bot)
v3: No change
---
src/shared/vcp.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/shared/vcp.c b/src/shared/vcp.c
index aa75f498a..e656615cc 100644
--- a/src/shared/vcp.c
+++ b/src/shared/vcp.c
@@ -32,9 +32,13 @@

#define VCP_STEP_SIZE 1

+#define VOCS_VOL_OFFSET_UPPER_LIMIT 255
+#define VOCS_VOL_OFFSET_LOWER_LIMIT -255
+
/* Apllication Error Code */
#define BT_ATT_ERROR_INVALID_CHANGE_COUNTER 0x80
#define BT_ATT_ERROR_OPCODE_NOT_SUPPORTED 0x81
+#define BT_ATT_ERROR_VALUE_OUT_OF_RANGE 0x82

#define BT_VCP_NA 0x00000000
#define BT_VCP_FRONT_LEFT 0x00000001
@@ -100,7 +104,7 @@ struct bt_vcs_ab_vol {

struct bt_vocs_set_vol_off {
uint8_t change_counter;
- uint8_t set_vol_offset;
+ int16_t set_vol_offset;
} __packed;

struct bt_vcp_cb {
@@ -167,7 +171,7 @@ struct bt_vcs {

/* Contains local bt_vcp_db */
struct vol_offset_state {
- uint16_t vol_offset;
+ int16_t vol_offset;
uint8_t counter;
} __packed;

@@ -705,6 +709,11 @@ static uint8_t vocs_set_vol_offset(struct bt_vocs *vocs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}

+ if (req->set_vol_offset > VOCS_VOL_OFFSET_UPPER_LIMIT ||
+ req->set_vol_offset < VOCS_VOL_OFFSET_LOWER_LIMIT) {
+ DBG(vcp, "error: Value Out of Range");
+ return BT_ATT_ERROR_VALUE_OUT_OF_RANGE;
+ }
vstate->vol_offset = req->set_vol_offset;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/

@@ -971,7 +980,7 @@ static void vocs_voaodec_read(struct gatt_db_attribute *attrib,
iov.iov_len);
}

-static struct bt_vcs *vcs_new(struct gatt_db *db)
+static struct bt_vcs *vcs_new(struct gatt_db *db, struct bt_vcp_db *vdb)
{
struct bt_vcs *vcs;
struct vol_state *vstate;
@@ -990,6 +999,8 @@ static struct bt_vcs *vcs_new(struct gatt_db *db)
/* Populate DB with VCS attributes */
bt_uuid16_create(&uuid, VCS_UUID);
vcs->service = gatt_db_add_service(db, &uuid, true, 9);
+ gatt_db_service_add_included(vcs->service, vdb->vocs->service);
+ gatt_db_service_set_active(vdb->vocs->service, true);

bt_uuid16_create(&uuid, VOL_STATE_CHRC_UUID);
vcs->vs = gatt_db_service_add_characteristic(vcs->service,
@@ -1048,7 +1059,8 @@ static struct bt_vocs *vocs_new(struct gatt_db *db)

/* Populate DB with VOCS attributes */
bt_uuid16_create(&uuid, VOL_OFFSET_CS_UUID);
- vocs->service = gatt_db_add_service(db, &uuid, true, 9);
+
+ vocs->service = gatt_db_add_service(db, &uuid, false, 12);

bt_uuid16_create(&uuid, VOCS_STATE_CHAR_UUID);
vocs->vos = gatt_db_service_add_characteristic(vocs->service,
@@ -1110,11 +1122,10 @@ static struct bt_vcp_db *vcp_db_new(struct gatt_db *db)
if (!vcp_db)
vcp_db = queue_new();

- vdb->vcs = vcs_new(db);
- vdb->vcs->vdb = vdb;
-
vdb->vocs = vocs_new(db);
vdb->vocs->vdb = vdb;
+ vdb->vcs = vcs_new(db, vdb);
+ vdb->vcs->vdb = vdb;

queue_push_tail(vcp_db, vdb);

--
2.34.1