From 800d216222274b67da30a32d55072154f0b79c5a Mon Sep 17 00:00:00 2001 From: jjoseph Date: Tue, 29 Jun 2021 11:00:37 +0530 Subject: [PATCH] bbf : Fix Inconsistent MACAddress case --- dmtree/tr181/ethernet.c | 14 +++++++++++++- libbbf_api/dmcommon.c | 11 ++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index f773a939..52cba21c 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -1075,7 +1075,19 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void static int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "mac", value); + char *mac_addr; + char address[64] = {0}; + int i; + + dmuci_get_value_by_section_string((struct uci_section *)data, "mac", &mac_addr); + strncpy(address, mac_addr, sizeof(address)); + for (i = 0; address[i] != '\0'; i++) { + if(address[i] >= 'a' && address[i] <= 'z') { + address[i] = address[i] - 32; + } + } + + *value = dmstrdup(address); return 0; } diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index fd7a58b7..3e2f641a 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -1016,10 +1016,19 @@ int get_net_device_sysfs(const char *device, const char *name, char **value) { if (device && device[0]) { char file[256]; - char val[64]; + char val[64] = {0}; snprintf(file, sizeof(file), "/sys/class/net/%s/%s", device, name); dm_read_sysfs_file(file, val, sizeof(val)); + if (0 == strcmp(name, "address")) { + // Convert the mac address to upper case. + int i; + for (i = 0; val[i] != '\0'; i++) { + if (val[i] >= 'a' && val[i] <= 'z') { + val[i] = val[i] - 32; + } + } + } *value = dmstrdup(val); } else { *value = "0";