+static inline uint8_t blobmsg_get_u8(struct blob_attr *attr)
+{
+ return *(uint8_t *) blobmsg_data(attr);
+}
+
+static inline bool blobmsg_get_bool(struct blob_attr *attr)
+{
+ return *(uint8_t *) blobmsg_data(attr);
+}
+
+static inline uint16_t blobmsg_get_u16(struct blob_attr *attr)
+{
+ return be16_to_cpu(*(uint16_t *) blobmsg_data(attr));
+}
+
+static inline uint32_t blobmsg_get_u32(struct blob_attr *attr)
+{
+ return be32_to_cpu(*(uint32_t *) blobmsg_data(attr));
+}
+
+static inline uint64_t blobmsg_get_u64(struct blob_attr *attr)
+{
+ uint32_t *ptr = (uint32_t *) blobmsg_data(attr);
+ uint64_t tmp = ((uint64_t) be32_to_cpu(ptr[0])) << 32;
+ tmp |= be32_to_cpu(ptr[1]);
+ return tmp;
+}
+
+static inline uint64_t blobmsg_cast_u64(struct blob_attr *attr)
+{
+ uint64_t tmp = 0;
+
+ if (blobmsg_type(attr) == BLOBMSG_TYPE_INT64)
+ tmp = blobmsg_get_u64(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32)
+ tmp = blobmsg_get_u32(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16)
+ tmp = blobmsg_get_u16(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8)
+ tmp = blobmsg_get_u8(attr);
+
+ return tmp;
+}
+
+static inline int64_t blobmsg_cast_s64(struct blob_attr *attr)
+{
+ int64_t tmp = 0;
+
+ if (blobmsg_type(attr) == BLOBMSG_TYPE_INT64)
+ tmp = blobmsg_get_u64(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32)
+ tmp = (int32_t)blobmsg_get_u32(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16)
+ tmp = (int16_t)blobmsg_get_u16(attr);
+ else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8)
+ tmp = (int8_t)blobmsg_get_u8(attr);
+
+ return tmp;
+}
+
+static inline double blobmsg_get_double(struct blob_attr *attr)
+{
+ union {
+ double d;
+ uint64_t u64;
+ } v;
+ v.u64 = blobmsg_get_u64(attr);
+ return v.d;
+}
+
+static inline char *blobmsg_get_string(struct blob_attr *attr)
+{
+ if (!attr)
+ return NULL;
+
+ return (char *) blobmsg_data(attr);
+}
+
+void *blobmsg_alloc_string_buffer(struct blob_buf *buf, const char *name, unsigned int maxlen);
+void *blobmsg_realloc_string_buffer(struct blob_buf *buf, unsigned int maxlen);
+void blobmsg_add_string_buffer(struct blob_buf *buf);
+
+int blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg);
+int blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
+ __attribute__((format(printf, 3, 4)));
+
+#define blobmsg_for_each_attr(pos, attr, rem) \
+ for (rem = attr ? blobmsg_data_len(attr) : 0, \
+ pos = (struct blob_attr *) (attr ? blobmsg_data(attr) : NULL); \
+ rem >= sizeof(struct blob_attr) && (blob_pad_len(pos) <= rem) && \
+ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \
+ rem -= blob_pad_len(pos), pos = blob_next(pos))
+
+#define __blobmsg_for_each_attr(pos, attr, rem) \
+ for (pos = (struct blob_attr *) (attr ? blobmsg_data(attr) : NULL); \
+ rem >= sizeof(struct blob_attr) && (blob_pad_len(pos) <= rem) && \
+ (blob_pad_len(pos) >= sizeof(struct blob_attr)); \
+ rem -= blob_pad_len(pos), pos = blob_next(pos))
+