From: mengdong.lin@linux.intel.com
To: alsa-devel@alsa-project.org, broonie@kernel.org
Cc: Mengdong Lin <mengdong.lin@linux.intel.com>,
tiwai@suse.de, mengdong.lin@intel.com, o-takashi@sakamocchi.jp,
liam.r.girdwood@intel.com, shreyas.nc@intel.com
Subject: [PATCH v2 3/5] topology: Change uuid value to 16 separate characters in text conf file
Date: Fri, 15 Jul 2016 20:18:59 +0800 [thread overview]
Message-ID: <46db82640cbbedcb13fb6fbc382772a9d66f139d.1468583255.git.mengdong.lin@linux.intel.com> (raw)
In-Reply-To: <cover.1468583255.git.mengdong.lin@linux.intel.com>
From: Mengdong Lin <mengdong.lin@linux.intel.com>
Previously in text conf file, the uuid value of vendor tuples is a
16-characer string. Now change it to 16 characters separated by commas,
easier for users to edit it manually.
Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
diff --git a/include/topology.h b/include/topology.h
index d666505..89bed6c 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -273,8 +273,8 @@ extern "C" {
* ...
* }
*
- * tuples."uuid" {
- * VENDOR_TOKEN_ID2 "16 character uuid"
+ * tuples."uuid" { # 16 characters separated by commas
+ * VENDOR_TOKEN_ID2 "0x01,0x02,...,0x0f"
* ...
* }
*
diff --git a/src/topology/data.c b/src/topology/data.c
index e60114e..a0c5ea2 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -176,6 +176,49 @@ static int get_hex_num(const char *str)
return values;
}
+/* get uuid from a string made by 16 characters separated by commas */
+static int get_uuid(const char *str, unsigned char *uuid_le)
+{
+ unsigned long int val;
+ char *tmp, *s = NULL;
+ int values = 0, ret = 0;
+
+ tmp = strdup(str);
+ if (tmp == NULL)
+ return -ENOMEM;
+
+ s = strtok(tmp, ",");
+
+ while (s != NULL) {
+ errno = 0;
+ val = strtoul(s, NULL, 0);
+ if ((errno == ERANGE && val == ULONG_MAX)
+ || (errno != 0 && val == 0)
+ || (val > UCHAR_MAX)) {
+ SNDERR("error: invalid value for uuid\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ *(uuid_le + values) = (unsigned char)val;
+
+ values++;
+ if (values >= 16)
+ break;
+
+ s = strtok(NULL, ",");
+ }
+
+ if (values < 16) {
+ SNDERR("error: less than 16 integers for uuid\n");
+ ret = -EINVAL;
+ }
+
+out:
+ free(tmp);
+ return ret;
+}
+
static int write_hex(char *buf, char *str, int width)
{
long val;
@@ -474,7 +517,7 @@ static int build_tuples(snd_tplg_t *tplg, struct tplg_elem *elem)
return 0;
}
-static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg,
+static int parse_tuple_set(snd_config_t *cfg,
struct tplg_tuple_set **s)
{
snd_config_iterator_t i, next;
@@ -484,7 +527,6 @@ static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg,
unsigned int type, num_tuples = 0;
struct tplg_tuple *tuple;
unsigned long int tuple_val;
- int len;
snd_config_get_id(cfg, &id);
@@ -535,14 +577,8 @@ static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg,
switch (type) {
case SND_SOC_TPLG_TUPLE_TYPE_UUID:
- len = strlen(value);
- if (len > 16 || len == 0) {
- SNDERR("error: tuple %s: invalid uuid\n", id);
+ if (get_uuid(value, tuple->uuid) < 0)
goto err;
- }
-
- memcpy(tuple->uuid, value, len);
- tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->uuid);
break;
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
@@ -598,7 +634,7 @@ err:
return -EINVAL;
}
-static int parse_tuple_sets(snd_tplg_t *tplg, snd_config_t *cfg,
+static int parse_tuple_sets(snd_config_t *cfg,
struct tplg_vendor_tuples *tuples)
{
snd_config_iterator_t i, next;
@@ -632,7 +668,7 @@ static int parse_tuple_sets(snd_tplg_t *tplg, snd_config_t *cfg,
return -EINVAL;
}
- err = parse_tuple_set(tplg, n, &tuples->set[tuples->num_sets]);
+ err = parse_tuple_set(n, &tuples->set[tuples->num_sets]);
if (err < 0)
return err;
@@ -774,7 +810,7 @@ int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg,
}
if (strcmp(id, "tuples") == 0) {
- err = parse_tuple_sets(tplg, n, tuples);
+ err = parse_tuple_sets(n, tuples);
if (err < 0)
return err;
}
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 518b81e..48db813 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -104,7 +104,7 @@ struct tplg_tuple {
char token[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
union {
char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
- char uuid[16];
+ unsigned char uuid[16];
unsigned int value;
};
};
--
2.5.0
next prev parent reply other threads:[~2016-07-15 12:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-15 12:17 [PATCH v2 0/5] topology: Enhance support for private data mengdong.lin
2016-07-15 12:17 ` [PATCH v2 1/5] topology: An element can refer to multipe data sections in text conf file mengdong.lin
2016-07-15 12:18 ` [PATCH v2 2/5] topology: Merge lookup for data reference into tplg_copy_data() mengdong.lin
2016-07-15 12:18 ` mengdong.lin [this message]
2016-07-15 12:19 ` [PATCH v2 4/5] topology: Parse vendor private data for manifest mengdong.lin
2016-07-15 12:19 ` [PATCH v2 5/5] topology: Tuple type can have an extenstion mengdong.lin
2016-07-16 12:58 ` [PATCH v2 0/5] topology: Enhance support for private data Takashi Sakamoto
2016-07-18 2:47 ` Mengdong Lin
2016-07-18 3:43 ` Takashi Sakamoto
2016-07-18 15:06 ` Lin, Mengdong
2016-07-19 3:59 ` Vinod Koul
2016-07-19 5:14 ` Takashi Sakamoto
2016-07-19 8:44 ` Lin, Mengdong
2016-07-17 8:03 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46db82640cbbedcb13fb6fbc382772a9d66f139d.1468583255.git.mengdong.lin@linux.intel.com \
--to=mengdong.lin@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=liam.r.girdwood@intel.com \
--cc=mengdong.lin@intel.com \
--cc=o-takashi@sakamocchi.jp \
--cc=shreyas.nc@intel.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).