summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Szewczyk <p.szewczyk@samsung.com>2018-05-15 16:32:56 +0200
committerPaweł Szewczyk <p.szewczyk@samsung.com>2018-05-15 18:14:37 +0200
commit4ceda10a566522db62fff929576cb9987a3f2d60 (patch)
treea30426001f32078bfee6eddfe6043eccfc77d8a6
parent1e6c112f1619a21ec6502c54c6260b7044e52462 (diff)
downloaddevice-manager-plugin-odroid-4ceda10a566522db62fff929576cb9987a3f2d60.tar.gz
device-manager-plugin-odroid-4ceda10a566522db62fff929576cb9987a3f2d60.tar.bz2
device-manager-plugin-odroid-4ceda10a566522db62fff929576cb9987a3f2d60.zip
The serial number is retrieved from /proc/cpuinfo and used as USB serial number string. Change-Id: Ibac051862011f697d7a63e8efeb5f50d0ea16c29 Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
-rwxr-xr-xhw/usb_gadget/usb_gadget.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/hw/usb_gadget/usb_gadget.c b/hw/usb_gadget/usb_gadget.c
index 00bd9a1..c412b8e 100755
--- a/hw/usb_gadget/usb_gadget.c
+++ b/hw/usb_gadget/usb_gadget.c
@@ -20,6 +20,7 @@
#include <hw/usb_gadget.h>
+#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -122,11 +123,52 @@ out:
return -ENOMEM;
}
+#define CPUINFO_DIR "/proc/cpuinfo"
+#define SERIAL_TAG "Serial"
+#define LINE_LEN 64
+
+static int get_device_serial(char **out)
+{
+ FILE *fp;
+ char line[LINE_LEN], *p, *q;
+
+ fp = fopen(CPUINFO_DIR, "r");
+ if (!fp)
+ return -1;
+
+ while ((p = fgets(line, LINE_LEN, fp)) != NULL) {
+ p = strchr(p, '\t');
+ if (!p)
+ continue;
+
+ *p = '\0';
+
+ if (strncmp(line, SERIAL_TAG, LINE_LEN) != 0)
+ continue;
+
+ ++p;
+ p = strchr(p, ':');
+ if (!p)
+ continue;
+ p += 2;
+
+ q = strchrnul(p, '\n');
+ *q = '\0';
+ *out = strdup(p);
+ fclose(fp);
+ return 0;
+ }
+
+ fclose(fp);
+ return -1;
+}
+
static int alloc_default_gadget(struct usb_gadget **_gadget)
{
struct usb_gadget *gadget;
struct usb_gadget_strings *strs;
struct usb_configuration **configs;
+ int ret;
gadget = zalloc(sizeof(*gadget));
if (!gadget)
@@ -143,7 +185,9 @@ static int alloc_default_gadget(struct usb_gadget **_gadget)
strs[0].lang_code = 0x409;
strs[0].manufacturer = strdup(DEFAULT_MANUFACTURER);
strs[0].product = strdup(DEFAULT_PRODUCT);
- strs[0].serial = strdup(DEFAULT_SERIAL);
+ ret = get_device_serial(&strs[0].serial);
+ if (ret < 0)
+ strs[0].serial = strdup(DEFAULT_SERIAL);
if (!strs[0].manufacturer || !strs[0].product || !strs[0].serial)
goto free_strs;