diff mbox

[OpenWrt-Devel] ar71xx: fix model string detection on NETGEAR WNDR3700/3800/WNDRMAC

Message ID 33a698b367be37f4ea6015162401f55161c4279e.1427142428.git.mschiffer@universe-factory.net
State Changes Requested
Headers show

Commit Message

Matthias Schiffer March 23, 2015, 8:27 p.m. UTC
There were a few issues with the existing code to detect the model string:
* Always using the string starting with byte 56 would cut off the W of WNDR when
  the ID starts with 29763654+16+128 instead of 29763654+16+64
* The string contained garbage after the zero byte instead of cutting it off
  after the zero (which wasn't always visible using busybox tools, but could
  confuse other scripts)

Tested on a WNDR3700v1 and WNDR3700v2. Unfortunately I couldn't find any devices
which use the $'\xff.....' branch, all newer revisions of the WNDR3700v2 and
WNDRMAC devices actually contain their model name in the ART and thus use
the * branch as well.

The [ -z "$model" ] check was dropped as there is no way to actually hit this
unless no ART is found at all.

The awk command was carefully crafted to work both with gawk and the (horribly
broken) busybox awk.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
---
 target/linux/ar71xx/base-files/lib/ar71xx.sh | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

Comments

Hannu Nyman March 25, 2015, 4:46 p.m. UTC | #1
I tested your code with my old WNDR3700 (v1), WNDR3700v2 and WNDR3800.
All three routers got detected ok.

My v2 is "old" and its art contents stop at byte 0x28, so it uses your "\xff" 
branch.

Just for reference, an old bug with discussion (from you?) about this issue:
https://dev.openwrt.org/ticket/18992


Ps.
I think that you mixed the explanation regarding the old logic: The first W 
gets cut away when the ID is shorter, not when it is longer. 3800 would have 
"...+128WND..." and correct ID, but new 3700v2 would have "...+64WNDR..." at 
the same place and the detected ID would miss the first W.
Matthias Schiffer March 25, 2015, 4:53 p.m. UTC | #2
On 03/25/2015 05:46 PM, Hannu Nyman wrote:
> I tested your code with my old WNDR3700 (v1), WNDR3700v2 and WNDR3800.
> All three routers got detected ok.
> 
> My v2 is "old" and its art contents stop at byte 0x28, so it uses your
> "\xff" branch.
Ah, can you send my a dump of your ART? Then I can hopefully simplify
the patch a bit.

> 
> Just for reference, an old bug with discussion (from you?) about this
> issue:
> https://dev.openwrt.org/ticket/18992
Yes, that's from me.

> 
> 
> Ps.
> I think that you mixed the explanation regarding the old logic: The
> first W gets cut away when the ID is shorter, not when it is longer.
> 3800 would have "...+128WND..." and correct ID, but new 3700v2 would
> have "...+64WNDR..." at the same place and the detected ID would miss
> the first W.
Yes, you're right. If I send a v2 of this, I'll fix the explanation.
diff mbox

Patch

diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index d2fe6ef..4781dd7 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -37,16 +37,28 @@  wndr3700_board_detect() {
 		machine="NETGEAR WNDR3700"
 		;;
 	"33373031")
-		local model
-		model=$(ar71xx_get_mtd_offset_size_format art 56 10 %c)
-		if [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ]; then
+		case "$(ar71xx_get_mtd_offset_size_format art 56 10 %c)" in
+		$'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
 			machine="NETGEAR WNDR3700v2"
-		elif [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xffN' ]; then
+			;;
+		$'\xff\xff\xff\xff\xff\xff\xff\xff\xffN')
 			machine="NETGEAR WNDRMAC"
-		else
-			machine="NETGEAR $model"
-		fi
-		;;
+			;;
+		*)
+			# Use awk to remove everything after the first zero byte
+			model="$(ar71xx_get_mtd_offset_size_format art 41 32 %c | awk 'BEGIN{FS="[[:cntrl:]]"} {print $1; exit}')"
+			case $model in
+			'29763654+16+64'*)
+				machine="NETGEAR ${model:14}"
+				;;
+			'29763654+16+128'*)
+				machine="NETGEAR ${model:15}"
+				;;
+			*)
+				# Unknown ID
+				machine="NETGEAR $model"
+			esac
+		esac
 	esac
 
 	AR71XX_BOARD_NAME="$name"