aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt61pci.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2009-01-27 18:33:47 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-02-09 15:03:35 -0500
commit0cbe0064614ace61e08618948f82c6d525e75017 (patch)
treedc6f68d5da42ab6ada2fab2bd4e5fecfa6f1ed8c /drivers/net/wireless/rt2x00/rt61pci.c
parenta2c9b652a12a550d3d8509e9bae43bac396c5076 (diff)
rt2x00: Validate firmware in driver
The get_firmware_crc() callback function isn't flexible enough when dealing with multiple firmware versions. It might in some cases be possible that the firmware file contains multiple CRC checksums. Create the check_firmware() callback function where the driver has complete freedom in how to validate the firmware. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt61pci.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index c7ad1b3d4765..0be147f364e7 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -1176,34 +1176,41 @@ static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1176 return fw_name; 1176 return fw_name;
1177} 1177}
1178 1178
1179static u16 rt61pci_get_firmware_crc(const void *data, const size_t len) 1179static int rt61pci_check_firmware(struct rt2x00_dev *rt2x00dev,
1180 const u8 *data, const size_t len)
1180{ 1181{
1182 u16 fw_crc;
1181 u16 crc; 1183 u16 crc;
1182 1184
1183 /* 1185 /*
1184 * Use the crc itu-t algorithm. 1186 * Only support 8kb firmware files.
1187 */
1188 if (len != 8192)
1189 return FW_BAD_LENGTH;
1190
1191 /*
1185 * The last 2 bytes in the firmware array are the crc checksum itself, 1192 * The last 2 bytes in the firmware array are the crc checksum itself,
1186 * this means that we should never pass those 2 bytes to the crc 1193 * this means that we should never pass those 2 bytes to the crc
1187 * algorithm. 1194 * algorithm.
1188 */ 1195 */
1196 fw_crc = (data[len - 2] << 8 | data[len - 1]);
1197
1198 /*
1199 * Use the crc itu-t algorithm.
1200 */
1189 crc = crc_itu_t(0, data, len - 2); 1201 crc = crc_itu_t(0, data, len - 2);
1190 crc = crc_itu_t_byte(crc, 0); 1202 crc = crc_itu_t_byte(crc, 0);
1191 crc = crc_itu_t_byte(crc, 0); 1203 crc = crc_itu_t_byte(crc, 0);
1192 1204
1193 return crc; 1205 return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
1194} 1206}
1195 1207
1196static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data, 1208static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev,
1197 const size_t len) 1209 const u8 *data, const size_t len)
1198{ 1210{
1199 int i; 1211 int i;
1200 u32 reg; 1212 u32 reg;
1201 1213
1202 if (len != 8192) {
1203 ERROR(rt2x00dev, "Invalid firmware file length (len=%zu)\n", len);
1204 return -ENOENT;
1205 }
1206
1207 /* 1214 /*
1208 * Wait for stable hardware. 1215 * Wait for stable hardware.
1209 */ 1216 */
@@ -2750,7 +2757,7 @@ static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
2750 .irq_handler = rt61pci_interrupt, 2757 .irq_handler = rt61pci_interrupt,
2751 .probe_hw = rt61pci_probe_hw, 2758 .probe_hw = rt61pci_probe_hw,
2752 .get_firmware_name = rt61pci_get_firmware_name, 2759 .get_firmware_name = rt61pci_get_firmware_name,
2753 .get_firmware_crc = rt61pci_get_firmware_crc, 2760 .check_firmware = rt61pci_check_firmware,
2754 .load_firmware = rt61pci_load_firmware, 2761 .load_firmware = rt61pci_load_firmware,
2755 .initialize = rt2x00pci_initialize, 2762 .initialize = rt2x00pci_initialize,
2756 .uninitialize = rt2x00pci_uninitialize, 2763 .uninitialize = rt2x00pci_uninitialize,