ndisgen vs binary INF file

I tried to generate a network driver for my TP-Link TL-WN727N USB WiFi adapter using ndisgen on my 9.2-STABLE amd64 system. I have the necessary rt2870.inf and rt2870.sys files from the Windows XP driver, but ndisgen says that the INF file format is not recognized. I looked at /usr/sbin/ndisgen and tried to replicate its INF file validation on the command line:

Code:
$ egrep -i -c "S.i.g.n.a.t.u.r.e" rt2870.inf
0

but...

Code:
$ egrep -c "S.i.g.n.a.t.u.r.e" rt2870.inf
1

As you see, the case-insensitive search (which is what ndisgen is doing) doesn't match, but a ase-sensitive search matches. I guess the fact that my rt2870.inf file is binary has something to do with this:

Code:
$ file ./rt2870.inf 
./rt2870.inf: Little-endian UTF-16 Unicode text, with CRLF, CR line terminators

I haven't yet been able to find a driver for this card with ASCII format inf file. Is ndisgen supposed to support binary INF files?
 
OK, I figured something out, but that only got me to another mystery.

My yesterday's tests were done in an environment with
Code:
LANG=en_US.UTF-8
If testing in environment where LANG is not set, the behaviour is as expected (both egrep -c and egrep -i -c match).

However, the actual command that ndisgen is using still doesn't match:

My yesterday's test command, more or less:
Code:
$ egrep -i -c ".S.i.g.n.a.t.u.r.e" rt2870.inf 
1

The actual command that is used by ndisgen:
Code:
$ egrep -i -c "Signature|.S.i.g.n.a.t.u.r.e" rt2870.inf
0

For the second night in a row, I have to go to sleep in a confused state ;)
 
Just a note, INF files are never binary, they are text-only. But it may not be ASCII but UTF-8 or Unicode.
 
Yes, it is not binary file but Unicode (actually UTF-16, which looked rather 'binary' when viewed with less) :)

After some further digging I discovered that this strange egrep behaviour affects BSD grep but not GNU grep. So I installed textproc/gnugrep and modified /usr/sbin/ndisgen to use that. Now I can successfully run ndisgen on some INF files that were rejected before, but when I try to convert the TP-Link driver that I actually need, the process ends with ndiscvt coredumping. So this INF file is probably broken.

How can I properly view/edit a text file in UTF-16 encoding on FreeBSD?
 
Back
Top