summaryrefslogtreecommitdiffstats
path: root/src/storage.c
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2008-09-13 20:12:32 -0700
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-09-13 20:12:32 -0700
commitdca79443166a7b2e28bd59a756cc9ad4ddcca270 (patch)
tree7fd2a500721dcd4acce8e0a24729cf8cfc9588fc /src/storage.c
parent653b7bfee4d6b5e39f2693c4354bfbf1bc4ddce0 (diff)
Add storage for pnp info, which can come from PNP record or EIR
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c
index 0690fc1a..559c3b12 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -810,3 +810,57 @@ int delete_record(const gchar *src, const gchar *dst, const uint32_t handle)
return textfile_del(filename, key);
}
+
+int store_pnp(const gchar *src, const gchar *dst, const uint16_t vendor,
+ const uint16_t product, const uint16_t version)
+{
+ char filename[PATH_MAX + 1], str[15];
+
+ create_name(filename, PATH_MAX, STORAGEDIR, src, "pnp");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ snprintf(str, sizeof(str), "%04X %04X %04X", vendor, product, version);
+
+ return textfile_put(filename, dst, str);
+}
+
+int read_pnp(const gchar *src, const gchar *dst, uint32_t *vendor,
+ uint16_t *product, uint16_t *version)
+{
+ char filename[PATH_MAX + 1];
+ char *str, *product_str, *version_str;
+
+ create_name(filename, PATH_MAX, STORAGEDIR, src, "pnp");
+
+ str = textfile_get(filename, dst);
+
+ if (!str)
+ return -ENOENT;
+
+ product_str = strchr(str, ' ');
+ if (!product_str) {
+ free(str);
+ return -ENOENT;
+ }
+ *(product_str++) = 0;
+
+ version_str = strchr(product_str, ' ');
+ if (!version_str) {
+ free(str);
+ return -ENOENT;
+ }
+ *(version_str++) = 0;
+
+ if (vendor)
+ *vendor = (uint16_t) strtol(str, NULL, 16);
+
+ if (product)
+ *product = (uint16_t) strtol(product_str, NULL, 16);
+
+ if (version)
+ *version = (uint16_t) strtol(version_str, NULL, 16);
+
+ free(str);
+ return 0;
+}