Unbreak the endian issue in firmware header decoding. Comfirmed good and

running by a powerpc machine.
This commit is contained in:
nisimura 2012-03-21 00:29:39 +00:00
parent e86314f733
commit 890bbdede1

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_iwi.c,v 1.89 2012/01/30 19:41:20 drochner Exp $ */ /* $NetBSD: if_iwi.c,v 1.90 2012/03/21 00:29:39 nisimura Exp $ */
/* $OpenBSD: if_iwi.c,v 1.111 2010/11/15 19:11:57 damien Exp $ */ /* $OpenBSD: if_iwi.c,v 1.111 2010/11/15 19:11:57 damien Exp $ */
/*- /*-
@ -19,7 +19,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.89 2012/01/30 19:41:20 drochner Exp $"); __KERNEL_RCSID(0, "$NetBSD: if_iwi.c,v 1.90 2012/03/21 00:29:39 nisimura Exp $");
/*- /*-
* Intel(R) PRO/Wireless 2200BG/2225BG/2915ABG driver * Intel(R) PRO/Wireless 2200BG/2225BG/2915ABG driver
@ -2154,7 +2154,7 @@ iwi_cache_firmware(struct iwi_softc *sc)
{ {
struct iwi_firmware *kfw = &sc->fw; struct iwi_firmware *kfw = &sc->fw;
firmware_handle_t fwh; firmware_handle_t fwh;
const struct iwi_firmware_hdr *hdr; struct iwi_firmware_hdr *hdr;
off_t size; off_t size;
char *fw; char *fw;
int error; int error;
@ -2192,8 +2192,12 @@ iwi_cache_firmware(struct iwi_softc *sc)
if (error != 0) if (error != 0)
goto fail2; goto fail2;
hdr = (struct iwi_firmware_hdr *)sc->sc_blob;
hdr->version = le32toh(hdr->version);
hdr->bsize = le32toh(hdr->bsize);
hdr->usize = le32toh(hdr->usize);
hdr->fsize = le32toh(hdr->fsize);
hdr = (const struct iwi_firmware_hdr *)sc->sc_blob;
if (size < sizeof(struct iwi_firmware_hdr) + hdr->bsize + hdr->usize + hdr->fsize) { if (size < sizeof(struct iwi_firmware_hdr) + hdr->bsize + hdr->usize + hdr->fsize) {
aprint_error_dev(sc->sc_dev, "image '%s' too small\n", aprint_error_dev(sc->sc_dev, "image '%s' too small\n",
sc->sc_fwname); sc->sc_fwname);
@ -2201,14 +2205,13 @@ iwi_cache_firmware(struct iwi_softc *sc)
goto fail2; goto fail2;
} }
hdr = (const struct iwi_firmware_hdr *)sc->sc_blob; DPRINTF(("firmware version = %d\n", hdr->version));
DPRINTF(("firmware version = %d\n", le32toh(hdr->version))); if ((IWI_FW_GET_MAJOR(hdr->version) != IWI_FW_REQ_MAJOR) ||
if ((IWI_FW_GET_MAJOR(le32toh(hdr->version)) != IWI_FW_REQ_MAJOR) || (IWI_FW_GET_MINOR(hdr->version) != IWI_FW_REQ_MINOR)) {
(IWI_FW_GET_MINOR(le32toh(hdr->version)) != IWI_FW_REQ_MINOR)) {
aprint_error_dev(sc->sc_dev, aprint_error_dev(sc->sc_dev,
"version for '%s' %d.%d != %d.%d\n", sc->sc_fwname, "version for '%s' %d.%d != %d.%d\n", sc->sc_fwname,
IWI_FW_GET_MAJOR(le32toh(hdr->version)), IWI_FW_GET_MAJOR(hdr->version),
IWI_FW_GET_MINOR(le32toh(hdr->version)), IWI_FW_GET_MINOR(hdr->version),
IWI_FW_REQ_MAJOR, IWI_FW_REQ_MINOR); IWI_FW_REQ_MAJOR, IWI_FW_REQ_MINOR);
error = EIO; error = EIO;
goto fail2; goto fail2;