|
41 | 41 |
|
42 | 42 | #include "mei.h"
|
43 | 43 |
|
| 44 | +#ifndef BIT |
| 45 | +#define BIT(x) (1 << (x)) |
| 46 | +#endif |
| 47 | + |
| 48 | +#define DEV_NAME_SIZE sizeof(((struct dirent *)0)->d_name) |
| 49 | + |
44 | 50 | #ifndef UUID_STR_LEN
|
45 | 51 | #define UUID_STR_LEN 37
|
46 | 52 | #endif
|
@@ -146,3 +152,72 @@ refcnt_put(const struct refcnt *ref)
|
146 | 152 | if (__sync_sub_and_fetch((int *)&ref->count, 1) == 0)
|
147 | 153 | ref->destroy(ref);
|
148 | 154 | }
|
| 155 | + |
| 156 | +static int mei_sysfs_read_property_file(const char *fname, char *buf, size_t sz) |
| 157 | +{ |
| 158 | + int fd; |
| 159 | + int rc; |
| 160 | + |
| 161 | + if (!buf) |
| 162 | + return -EINVAL; |
| 163 | + |
| 164 | + if (!sz) |
| 165 | + return 0; |
| 166 | + |
| 167 | + fd = open(fname, O_RDONLY); |
| 168 | + if (fd < 0) { |
| 169 | + DPRINTF("open failed %s %d\n", fname, errno); |
| 170 | + return -1; |
| 171 | + } |
| 172 | + |
| 173 | + rc = read(fd, buf, sz); |
| 174 | + |
| 175 | + close(fd); |
| 176 | + |
| 177 | + return rc; |
| 178 | +} |
| 179 | + |
| 180 | +static int mei_sysfs_read_property_u8(const char *fname, uint8_t *u8_property) |
| 181 | +{ |
| 182 | + char buf[4] = {0}; |
| 183 | + unsigned long int res; |
| 184 | + |
| 185 | + if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0) |
| 186 | + return -1; |
| 187 | + |
| 188 | + res = strtoul(buf, NULL, 10); |
| 189 | + if (res >= 256) |
| 190 | + return -1; |
| 191 | + |
| 192 | + *u8_property = (uint8_t)res; |
| 193 | + |
| 194 | + return 0; |
| 195 | +} |
| 196 | + |
| 197 | +static int mei_sysfs_read_property_u32(const char *fname, |
| 198 | + uint32_t *u32_property) |
| 199 | +{ |
| 200 | + char buf[32] = {0}; |
| 201 | + unsigned long int res; |
| 202 | + |
| 203 | + if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0) |
| 204 | + return -1; |
| 205 | + |
| 206 | + res = strtoul(buf, NULL, 10); |
| 207 | + if (res == ULONG_MAX) |
| 208 | + return -1; |
| 209 | + |
| 210 | + *u32_property = res; |
| 211 | + |
| 212 | + return 0; |
| 213 | +} |
| 214 | + |
| 215 | +static int mei_sysfs_read_property_uuid(char *fname, guid_t *uuid) |
| 216 | +{ |
| 217 | + char buf[UUID_STR_LEN] = {0}; |
| 218 | + |
| 219 | + if (mei_sysfs_read_property_file(fname, buf, sizeof(buf) - 1) < 0) |
| 220 | + return -1; |
| 221 | + |
| 222 | + return guid_parse(buf, sizeof(buf), uuid); |
| 223 | +} |
0 commit comments