From 18efbfcca3a01bb1267a5bf690756530650675fe Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Fri, 13 Jul 2018 15:50:38 +0300 Subject: [PATCH] [android] Normalize numerical id-values to lower case hex. JB#41748 Configfs wants to have numbers in '0xbeef' form while android usb wants to have 'beef'. Normalizing the output to expected format allows either form to be used in usb-moded configuration files. Signed-off-by: Simo Piiroinen --- src/usb_moded-android.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/usb_moded-android.c b/src/usb_moded-android.c index d3a269a..a2e8fac 100644 --- a/src/usb_moded-android.c +++ b/src/usb_moded-android.c @@ -267,7 +267,15 @@ bool android_set_productid(const char *id) { bool ack = false; + if( id && android_in_use() ) { + char str[16]; + char *end = 0; + unsigned num = strtol(id, &end, 16); + if( end > id && *end == 0 ) { + snprintf(str, sizeof str, "%04x", num); + id = str; + } ack = write_to_file(ANDROID0_ID_PRODUCT, id) != -1; } log_debug("ANDROID %s(%s) -> %d", __func__, id, ack); @@ -283,6 +291,13 @@ android_set_vendorid(const char *id) { bool ack = false; if( id && android_in_use() ) { + char str[16]; + char *end = 0; + unsigned num = strtol(id, &end, 16); + if( end > id && *end == 0 ) { + snprintf(str, sizeof str, "%04x", num); + id = str; + } ack = write_to_file(ANDROID0_ID_VENDOR, id) != -1; } log_debug("ANDROID %s(%s) -> %d", __func__, id, ack);