Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 134372
b: refs/heads/master
c: 0cbe006
h: refs/heads/master
v: v3
  • Loading branch information
Ivo van Doorn authored and John W. Linville committed Feb 9, 2009
1 parent b93b41b commit af369b6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a2c9b652a12a550d3d8509e9bae43bac396c5076
refs/heads/master: 0cbe0064614ace61e08618948f82c6d525e75017
7 changes: 4 additions & 3 deletions trunk/drivers/net/wireless/rt2x00/rt2x00.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@ struct rt2x00lib_ops {
*/
int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
u16 (*get_firmware_crc) (const void *data, const size_t len);
int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const void *data,
const size_t len);
int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len);
int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len);

/*
* Device initialization/deinitialization handlers.
Expand Down
27 changes: 18 additions & 9 deletions trunk/drivers/net/wireless/rt2x00/rt2x00firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
const struct firmware *fw;
char *fw_name;
int retval;
u16 crc;

/*
* Read correct firmware from harddisk.
Expand All @@ -61,24 +60,34 @@ static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
return -ENOENT;
}

crc = rt2x00dev->ops->lib->get_firmware_crc(fw->data, fw->size);
if (crc != (fw->data[fw->size - 2] << 8 | fw->data[fw->size - 1])) {
ERROR(rt2x00dev, "Firmware checksum error.\n");
retval = -ENOENT;
goto exit;
}

INFO(rt2x00dev, "Firmware detected - version: %d.%d.\n",
fw->data[fw->size - 4], fw->data[fw->size - 3]);

retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size);
switch (retval) {
case FW_OK:
break;
case FW_BAD_CRC:
ERROR(rt2x00dev, "Firmware checksum error.\n");
goto exit;
case FW_BAD_LENGTH:
ERROR(rt2x00dev,
"Invalid firmware file length (len=%zu)\n", fw->size);
goto exit;
case FW_BAD_VERSION:
ERROR(rt2x00dev,
"Current firmware does not support detected chipset.\n");
goto exit;
};

rt2x00dev->fw = fw;

return 0;

exit:
release_firmware(fw);

return retval;
return -ENOENT;
}

int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
Expand Down
10 changes: 10 additions & 0 deletions trunk/drivers/net/wireless/rt2x00/rt2x00reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ enum rate_modulation {
RATE_MODE_HT_GREENFIELD = 3,
};

/*
* Firmware validation error codes
*/
enum firmware_errors {
FW_OK,
FW_BAD_CRC,
FW_BAD_LENGTH,
FW_BAD_VERSION,
};

/*
* Register handlers.
* We store the position of a register field inside a field structure,
Expand Down
29 changes: 18 additions & 11 deletions trunk/drivers/net/wireless/rt2x00/rt61pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,34 +1176,41 @@ static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
return fw_name;
}

static u16 rt61pci_get_firmware_crc(const void *data, const size_t len)
static int rt61pci_check_firmware(struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len)
{
u16 fw_crc;
u16 crc;

/*
* Use the crc itu-t algorithm.
* Only support 8kb firmware files.
*/
if (len != 8192)
return FW_BAD_LENGTH;

/*
* The last 2 bytes in the firmware array are the crc checksum itself,
* this means that we should never pass those 2 bytes to the crc
* algorithm.
*/
fw_crc = (data[len - 2] << 8 | data[len - 1]);

/*
* Use the crc itu-t algorithm.
*/
crc = crc_itu_t(0, data, len - 2);
crc = crc_itu_t_byte(crc, 0);
crc = crc_itu_t_byte(crc, 0);

return crc;
return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
}

static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data,
const size_t len)
static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len)
{
int i;
u32 reg;

if (len != 8192) {
ERROR(rt2x00dev, "Invalid firmware file length (len=%zu)\n", len);
return -ENOENT;
}

/*
* Wait for stable hardware.
*/
Expand Down Expand Up @@ -2750,7 +2757,7 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
.irq_handler = rt61pci_interrupt,
.probe_hw = rt61pci_probe_hw,
.get_firmware_name = rt61pci_get_firmware_name,
.get_firmware_crc = rt61pci_get_firmware_crc,
.check_firmware = rt61pci_check_firmware,
.load_firmware = rt61pci_load_firmware,
.initialize = rt2x00pci_initialize,
.uninitialize = rt2x00pci_uninitialize,
Expand Down
29 changes: 18 additions & 11 deletions trunk/drivers/net/wireless/rt2x00/rt73usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,35 +1061,42 @@ static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
return FIRMWARE_RT2571;
}

static u16 rt73usb_get_firmware_crc(const void *data, const size_t len)
static int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len)
{
u16 fw_crc;
u16 crc;

/*
* Use the crc itu-t algorithm.
* Only support 2kb firmware files.
*/
if (len != 2048)
return FW_BAD_LENGTH;

/*
* The last 2 bytes in the firmware array are the crc checksum itself,
* this means that we should never pass those 2 bytes to the crc
* algorithm.
*/
fw_crc = (data[len - 2] << 8 | data[len - 1]);

/*
* Use the crc itu-t algorithm.
*/
crc = crc_itu_t(0, data, len - 2);
crc = crc_itu_t_byte(crc, 0);
crc = crc_itu_t_byte(crc, 0);

return crc;
return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
}

static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data,
const size_t len)
static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev,
const u8 *data, const size_t len)
{
unsigned int i;
int status;
u32 reg;

if (len != 2048) {
ERROR(rt2x00dev, "Invalid firmware file length (len=%zu)\n", len);
return -ENOENT;
}

/*
* Wait for stable hardware.
*/
Expand Down Expand Up @@ -2278,7 +2285,7 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
.probe_hw = rt73usb_probe_hw,
.get_firmware_name = rt73usb_get_firmware_name,
.get_firmware_crc = rt73usb_get_firmware_crc,
.check_firmware = rt73usb_check_firmware,
.load_firmware = rt73usb_load_firmware,
.initialize = rt2x00usb_initialize,
.uninitialize = rt2x00usb_uninitialize,
Expand Down

0 comments on commit af369b6

Please sign in to comment.