[rdkb][common][app][Refactor mii-mgr tool]
[Description]
Refactor mii-mgr tool
1. align to newest openwrt version
2. add patch to fix getting wan status fail issue
[Release-log]
Change-Id: I83efbc922a4ed8a91ebcafd88bf6053bb7408794
diff --git a/recipes-devtools/mii-mgr/files/fix-rdkb-wan-get-status-fail.patch b/recipes-devtools/mii-mgr/files/fix-rdkb-wan-get-status-fail.patch
new file mode 100644
index 0000000..b1725c5
--- /dev/null
+++ b/recipes-devtools/mii-mgr/files/fix-rdkb-wan-get-status-fail.patch
@@ -0,0 +1,11 @@
+--- ../mii_mgr.c.bak 2022-11-03 15:21:40.446210000 +0800
++++ ../mii_mgr.c 2022-11-03 15:23:20.435803359 +0800
+@@ -118,7 +118,7 @@
+ is_priv = 0;
+ break;
+ case 'i':
+- strncpy(ifname, optarg, 5);
++ strncpy(ifname, optarg, IFNAMSIZ);
+ ifname[IFNAMSIZ - 1] = '\0';
+ break;
+ case 'p':
diff --git a/recipes-devtools/mii-mgr/files/src/Makefile b/recipes-devtools/mii-mgr/files/src/Makefile
new file mode 100644
index 0000000..55d6a6f
--- /dev/null
+++ b/recipes-devtools/mii-mgr/files/src/Makefile
@@ -0,0 +1,16 @@
+EXEC = mii_mgr
+
+CFLAGS += -Wall -Werror
+
+all: $(EXEC)
+
+mii_mgr: mii_mgr.o
+
+ $(CC) $(LDFLAGS) -o $@ $^
+
+romfs:
+ $(ROMFSINST) /bin/mii_mgr
+
+clean:
+ -rm -f $(EXEC) *.elf *.gdb *.o
+
diff --git a/recipes-devtools/mii-mgr/files/mii_mgr.c b/recipes-devtools/mii-mgr/files/src/mii_mgr.c
similarity index 92%
rename from recipes-devtools/mii-mgr/files/mii_mgr.c
rename to recipes-devtools/mii-mgr/files/src/mii_mgr.c
index f968807..a22c3e8 100644
--- a/recipes-devtools/mii-mgr/files/mii_mgr.c
+++ b/recipes-devtools/mii-mgr/files/src/mii_mgr.c
@@ -118,22 +118,30 @@
is_priv = 0;
break;
case 'i':
- strncpy(ifname, optarg, IFNAMSIZ);
+ strncpy(ifname, optarg, 5);
ifname[IFNAMSIZ - 1] = '\0';
break;
case 'p':
port = strtoul(optarg, NULL, 16);
+ if (port > INT_MAX)
+ return -EINVAL;
break;
- case 'd':
- dev = strtoul(optarg, NULL, 16);
+ case 'd':
+ dev = strtoul(optarg, NULL, 16);
+ if (dev > INT_MAX)
+ return -EINVAL;
is_cl45 = 1;
break;
case 'r':
reg_num = strtoul(optarg, NULL, 16);
+ if (reg_num > INT_MAX)
+ return -EINVAL;
break;
case 'v':
val = strtoul(optarg, NULL, 16);
+ if (val > INT_MAX)
+ return -EINVAL;
break;
case '?':
show_usage();
diff --git a/recipes-devtools/mii-mgr/files/mii_mgr.h b/recipes-devtools/mii-mgr/files/src/mii_mgr.h
similarity index 100%
rename from recipes-devtools/mii-mgr/files/mii_mgr.h
rename to recipes-devtools/mii-mgr/files/src/mii_mgr.h
diff --git a/recipes-devtools/mii-mgr/mii-mgr_1.0.bb b/recipes-devtools/mii-mgr/mii-mgr_1.0.bb
index 9a16340..c233ebe 100644
--- a/recipes-devtools/mii-mgr/mii-mgr_1.0.bb
+++ b/recipes-devtools/mii-mgr/mii-mgr_1.0.bb
@@ -3,20 +3,20 @@
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=c188eeeb69c0a05d0545816f1458a0c9"
-S = "${WORKDIR}"
-
SRC_URI = " \
- file://COPYING \
- file://mii_mgr.c \
- file://mii_mgr.h \
+ file://COPYING;subdir=git/src \
+ file://src;subdir=git \
+ file://fix-rdkb-wan-get-status-fail.patch \
"
+S = "${WORKDIR}/git/src"
+
do_compile() {
${CC} ${LDFLAGS} mii_mgr.c -o mii_mgr
}
do_install() {
install -d ${D}${sbindir}
- install -m 0755 ${WORKDIR}/mii_mgr ${D}${sbindir}
- install -m 0755 ${WORKDIR}/mii_mgr ${D}${sbindir}/mii_mgr_cl45
+ install -m 0755 ${S}/mii_mgr ${D}${sbindir}
+ install -m 0755 ${S}/mii_mgr ${D}${sbindir}/mii_mgr_cl45
}