summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Szewczyk <p.szewczyk@samsung.com>2018-05-15 17:10:05 +0200
committerPaweł Szewczyk <p.szewczyk@samsung.com>2018-05-15 17:32:27 +0200
commitd1bfb925ae2e93fb11c989563a1fd3442bd56844 (patch)
treece2c1fda6069691af27c9f1cd5d340def82677a3
parent482bb923f664faa69fa784f0cfddd4cfe8e97042 (diff)
downloaddevice-manager-plugin-artik-d1bfb925ae2e93fb11c989563a1fd3442bd56844.tar.gz
device-manager-plugin-artik-d1bfb925ae2e93fb11c989563a1fd3442bd56844.tar.bz2
device-manager-plugin-artik-d1bfb925ae2e93fb11c989563a1fd3442bd56844.zip
Serial number is retrieved from /sys/firmware/devicetree/base/serial-number file. Change-Id: I3e8251bd1ce916b72d45102017b3533420ef9f54 Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
-rwxr-xr-xhw/usb_gadget/usb_gadget.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/hw/usb_gadget/usb_gadget.c b/hw/usb_gadget/usb_gadget.c
index ad4513d..d1e6704 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,36 @@ out:
return -ENOMEM;
}
+#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number"
+#define LINE_LEN 64
+
+static int get_device_serial(char **out)
+{
+ FILE *fp;
+ char *line, *p;
+
+ fp = fopen(SERIAL_FILE_PATH, "r");
+ if (!fp)
+ return -1;
+
+ line = malloc(LINE_LEN);
+ p = fgets(line, LINE_LEN, fp);
+ fclose(fp);
+ if (p == NULL) {
+ free(line);
+ return -1;
+ }
+
+ *out = p;
+ return 0;
+}
+
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 +169,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;