diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-09-14 18:03:54 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-09-14 18:03:54 +0200 |
commit | a90bb1223be9413d5ef76a18d16bbc0de757ceda (patch) | |
tree | e6e02702aca1e0377515006905b3901701d9c9c0 /src/storage.c | |
parent | a6195ecddf5e2b284654ace85566ecd60ab06141 (diff) | |
parent | 6d7e8a0ee472260f615131154407561fbb615ec4 (diff) |
Merge branch 'master' of git://git.infradead.org/users/dwmw2/bluez
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 54 |
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; +} |