diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2008-09-13 20:12:32 -0700 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-09-13 20:12:32 -0700 |
commit | dca79443166a7b2e28bd59a756cc9ad4ddcca270 (patch) | |
tree | 7fd2a500721dcd4acce8e0a24729cf8cfc9588fc | |
parent | 653b7bfee4d6b5e39f2693c4354bfbf1bc4ddce0 (diff) |
Add storage for pnp info, which can come from PNP record or EIR
-rw-r--r-- | src/storage.c | 54 | ||||
-rw-r--r-- | src/storage.h | 5 |
2 files changed, 59 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; +} diff --git a/src/storage.h b/src/storage.h index 7f89ef19..a4eb82da 100644 --- a/src/storage.h +++ b/src/storage.h @@ -59,3 +59,8 @@ int delete_entry(bdaddr_t *src, const char *storage, const char *key); int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec); sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle); int delete_record(const gchar *src, const gchar *dst, const uint32_t handle); + +int store_pnp(const gchar *src, const gchar *dst, const uint16_t vendor, + const uint16_t product, const uint16_t version); +int read_pnp(const gchar *src, const gchar *dst, uint32_t *vendor, + uint16_t *product, uint16_t *version); |