# ndisgen vs binary INF file



## vatson (Dec 9, 2013)

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:


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

but...


```
$ 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:


```
$ 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?


----------



## vatson (Dec 10, 2013)

OK, I figured something out, but that only got me to another mystery.

My yesterday's tests were done in an environment with 
	
	



```
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: 
	
	



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

The actual command that is used by ndisgen:

```
$ 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


----------



## SirDice (Dec 11, 2013)

Just a note, INF files are never binary, they are text-only. But it may not be ASCII but UTF-8 or Unicode.


----------



## vatson (Dec 11, 2013)

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?


----------

