aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt73usb.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/rt73usb.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/rt73usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 24e97b341cf8..be791a43c054 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1061,35 +1061,42 @@ static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1061 return FIRMWARE_RT2571; 1061 return FIRMWARE_RT2571;
1062} 1062}
1063 1063
1064static u16 rt73usb_get_firmware_crc(const void *data, const size_t len) 1064static int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev,
1065 const u8 *data, const size_t len)
1065{ 1066{
1067 u16 fw_crc;
1066 u16 crc; 1068 u16 crc;
1067 1069
1068 /* 1070 /*
1069 * Use the crc itu-t algorithm. 1071 * Only support 2kb firmware files.
1072 */
1073 if (len != 2048)
1074 return FW_BAD_LENGTH;
1075
1076 /*
1070 * The last 2 bytes in the firmware array are the crc checksum itself, 1077 * The last 2 bytes in the firmware array are the crc checksum itself,
1071 * this means that we should never pass those 2 bytes to the crc 1078 * this means that we should never pass those 2 bytes to the crc
1072 * algorithm. 1079 * algorithm.
1073 */ 1080 */
1081 fw_crc = (data[len - 2] << 8 | data[len - 1]);
1082
1083 /*
1084 * Use the crc itu-t algorithm.
1085 */
1074 crc = crc_itu_t(0, data, len - 2); 1086 crc = crc_itu_t(0, data, len - 2);
1075 crc = crc_itu_t_byte(crc, 0); 1087 crc = crc_itu_t_byte(crc, 0);
1076 crc = crc_itu_t_byte(crc, 0); 1088 crc = crc_itu_t_byte(crc, 0);
1077 1089
1078 return crc; 1090 return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
1079} 1091}
1080 1092
1081static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data, 1093static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1082 const size_t len) 1094 const u8 *data, const size_t len)
1083{ 1095{
1084 unsigned int i; 1096 unsigned int i;
1085 int status; 1097 int status;
1086 u32 reg; 1098 u32 reg;
1087 1099
1088 if (len != 2048) {
1089 ERROR(rt2x00dev, "Invalid firmware file length (len=%zu)\n", len);
1090 return -ENOENT;
1091 }
1092
1093 /* 1100 /*
1094 * Wait for stable hardware. 1101 * Wait for stable hardware.
1095 */ 1102 */
@@ -2278,7 +2285,7 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
2278static const struct rt2x00lib_ops rt73usb_rt2x00_ops = { 2285static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
2279 .probe_hw = rt73usb_probe_hw, 2286 .probe_hw = rt73usb_probe_hw,
2280 .get_firmware_name = rt73usb_get_firmware_name, 2287 .get_firmware_name = rt73usb_get_firmware_name,
2281 .get_firmware_crc = rt73usb_get_firmware_crc, 2288 .check_firmware = rt73usb_check_firmware,
2282 .load_firmware = rt73usb_load_firmware, 2289 .load_firmware = rt73usb_load_firmware,
2283 .initialize = rt2x00usb_initialize, 2290 .initialize = rt2x00usb_initialize,
2284 .uninitialize = rt2x00usb_uninitialize, 2291 .uninitialize = rt2x00usb_uninitialize,