2 * Copyright 2010, Christian Lamparter <chunkeey@googlemail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <sys/types.h>
35 void (*func)(const struct carl9170fw_desc_head *, struct carlfw *fw);
38 #define CHECK_FOR_FEATURE(feature_enum) \
39 { .id = feature_enum, .name = #feature_enum, .func = NULL }
41 #define CHECK_FOR_FEATURE_FUNC(feature_enum, _func) \
42 { .id = feature_enum, .name = #feature_enum, .func = _func }
44 static const struct feature_list known_otus_features_v1[] = {
45 CHECK_FOR_FEATURE(CARL9170FW_DUMMY_FEATURE),
46 CHECK_FOR_FEATURE(CARL9170FW_UNUSABLE),
47 CHECK_FOR_FEATURE(CARL9170FW_COMMAND_PHY),
48 CHECK_FOR_FEATURE(CARL9170FW_COMMAND_CAM),
49 CHECK_FOR_FEATURE(CARL9170FW_WLANTX_CAB),
50 CHECK_FOR_FEATURE(CARL9170FW_HANDLE_BACK_REQ),
51 CHECK_FOR_FEATURE(CARL9170FW_GPIO_INTERRUPT),
52 CHECK_FOR_FEATURE(CARL9170FW_PSM),
55 static void check_feature_list(const struct carl9170fw_desc_head *head,
57 const struct feature_list *list,
58 const unsigned int entries,
63 for (i = 0; i < entries; i++) {
64 if (!carl9170fw_supports(bitmap, list[i].id))
67 fprintf(stdout, "\t\t%2d = %s\n", list[i].id, list[i].name);
69 list[i].func(head, fw);
73 static void show_otus_desc(const struct carl9170fw_desc_head *head,
76 const struct carl9170fw_otus_desc *otus = (const void *) head;
78 BUILD_BUG_ON(ARRAY_SIZE(known_otus_features_v1) != __CARL9170FW_FEATURE_NUM);
80 fprintf(stdout, "\tBeacon Address: %x, (reserved:%d Bytes)\n",
81 le32_to_cpu(otus->bcn_addr), le16_to_cpu(otus->bcn_len));
82 fprintf(stdout, "\tFirmware API Version: %d\n", otus->api_ver);
83 fprintf(stdout, "\tSupported Firmware Interfaces: %d\n", otus->vif_num);
85 fprintf(stdout, "\tSupported Features: (raw:%.08x)\n",
86 le32_to_cpu(otus->fw_feature_set));
88 check_feature_list(head, otus->fw_feature_set, known_otus_features_v1,
89 ARRAY_SIZE(known_otus_features_v1), fw);
92 static void show_miniboot_info(const struct carl9170fw_desc_head *head,
93 struct carlfw *fw __unused)
95 const struct carl9170fw_usb_desc *usb = (const void *) head;
97 fprintf(stdout, "\t\t\tminiboot size: %d Bytes\n", usb->miniboot_size);
100 static const struct feature_list known_usb_features_v1[] = {
101 CHECK_FOR_FEATURE(CARL9170FW_USB_DUMMY_FEATURE),
102 CHECK_FOR_FEATURE_FUNC(CARL9170FW_USB_MINIBOOT, show_miniboot_info),
103 CHECK_FOR_FEATURE(CARL9170FW_USB_INIT_FIRMWARE),
104 CHECK_FOR_FEATURE(CARL9170FW_USB_RESP_EP2),
105 CHECK_FOR_FEATURE(CARL9170FW_USB_DOWN_STREAM),
106 CHECK_FOR_FEATURE(CARL9170FW_USB_UP_STREAM),
107 CHECK_FOR_FEATURE(CARL9170FW_USB_WATCHDOG),
110 static void show_usb_desc(const struct carl9170fw_desc_head *head,
111 struct carlfw *fw __unused)
113 const struct carl9170fw_usb_desc *usb = (const void *) head;
115 BUILD_BUG_ON(ARRAY_SIZE(known_usb_features_v1) != __CARL9170FW_USB_FEATURE_NUM);
117 fprintf(stdout, "\tTX DMA chunk size:%d Bytes, TX DMA chunks:%d\n",
118 usb->tx_frag_len, usb->tx_descs);
119 fprintf(stdout, "\t=> %d Bytes are reserved for the TX queues\n",
120 usb->tx_frag_len * usb->tx_descs);
121 fprintf(stdout, "\tMax. RX stream block size:%d Bytes\n",
122 usb->rx_max_frame_len);
123 fprintf(stdout, "\tFirmware upload pointer: 0x%x\n",
125 fprintf(stdout, "\tSupported Features: (raw:%.08x)\n",
126 le32_to_cpu(usb->usb_feature_set));
128 check_feature_list(head, usb->usb_feature_set, known_usb_features_v1,
129 ARRAY_SIZE(known_usb_features_v1), fw);
132 static void show_motd_desc(const struct carl9170fw_desc_head *head,
133 struct carlfw *fw __unused)
135 const struct carl9170fw_motd_desc *motd = (const void *) head;
136 char buf[CARL9170FW_MOTD_STRING_LEN];
137 unsigned int fw_date;
139 fw_date = motd->fw_year_month_day;
140 fprintf(stdout, "\tFirmware Build Date (YYYY-MM-DD): 2%03d-%02d-%02d\n",
141 CARL9170FW_GET_YEAR(fw_date), CARL9170FW_GET_MONTH(fw_date),
142 CARL9170FW_GET_DAY(fw_date));
144 strncpy(buf, motd->desc, CARL9170FW_MOTD_STRING_LEN);
145 fprintf(stdout, "\tFirmware Text:\"%s\"\n", buf);
147 strncpy(buf, motd->release, CARL9170FW_MOTD_STRING_LEN);
148 fprintf(stdout, "\tFirmware Release:\"%s\"\n", buf);
151 static void show_fix_desc(const struct carl9170fw_desc_head *head,
152 struct carlfw *fw __unused)
154 const struct carl9170fw_fix_desc *fix = (const void *) head;
155 const struct carl9170fw_fix_entry *iter;
158 for (i = 0; i < (head->length - sizeof(*head)) / sizeof(*iter); i++) {
159 iter = &fix->data[i];
160 fprintf(stdout, "\t\t%d: 0x%.8x := 0x%.8x (0x%.8x)\n", i,
161 le32_to_cpu(iter->address), le32_to_cpu(iter->value),
162 le32_to_cpu(iter->mask));
166 static void show_dbg_desc(const struct carl9170fw_desc_head *head,
167 struct carlfw *fw __unused)
169 const struct carl9170fw_dbg_desc *dbg = (const void *) head;
171 fprintf(stdout, "\tFirmware Debug Registers/Counters\n");
172 fprintf(stdout, "\t\tbogoclock = 0x%.8x\n",
173 le32_to_cpu(dbg->bogoclock_addr));
174 fprintf(stdout, "\t\tcounter = 0x%.8x\n",
175 le32_to_cpu(dbg->counter_addr));
176 fprintf(stdout, "\t\trx total = 0x%.8x\n",
177 le32_to_cpu(dbg->rx_total_addr));
178 fprintf(stdout, "\t\trx overrun = 0x%.8x\n",
179 le32_to_cpu(dbg->rx_overrun_addr));
180 /* Nothing interesting here */
183 static void show_chk_desc(const struct carl9170fw_desc_head *head,
184 struct carlfw *fw __unused)
186 const struct carl9170fw_chk_desc *chk = (const void *) head;
188 fprintf(stdout, "\tFirmware Descriptor CRC32: %08x\n",
189 le32_to_cpu(chk->hdr_crc32));
190 fprintf(stdout, "\tFirmware Image CRC32: %08x\n",
191 le32_to_cpu(chk->fw_crc32));
194 static void show_last_desc(const struct carl9170fw_desc_head *head,
195 struct carlfw *fw __unused)
198 const struct carl9170fw_last_desc *last __unused = (const void *) head;
203 #define ADD_HANDLER(_magic, _func) \
205 .magic = _magic##_MAGIC, \
206 .min_ver = CARL9170FW_## _magic##_DESC_CUR_VER, \
208 .size = CARL9170FW_## _magic##_DESC_SIZE, \
211 static const struct {
214 void (*func)(const struct carl9170fw_desc_head *, struct carlfw *);
217 ADD_HANDLER(OTUS, show_otus_desc),
218 ADD_HANDLER(USB, show_usb_desc),
219 ADD_HANDLER(MOTD, show_motd_desc),
220 ADD_HANDLER(DBG, show_dbg_desc),
221 ADD_HANDLER(FIX, show_fix_desc),
222 ADD_HANDLER(CHK, show_chk_desc),
223 ADD_HANDLER(LAST, show_last_desc),
226 static const uint8_t otus_magic[4] = { OTUS_MAGIC };
228 static void show_desc_head(struct carl9170fw_desc_head *head)
230 #define P(c) (isprint(c) ? c : ' ')
232 fprintf(stdout, ">\t%c%c%c%c Descriptor: size:%d, compatible:%d, "
234 P(head->magic[0]), P(head->magic[1]), P(head->magic[2]),
235 P(head->magic[3]), le16_to_cpu(head->length), head->min_ver,
239 static void fwinfo_info(void)
241 fprintf(stderr, "Usage:\n");
242 fprintf(stderr, "\tfwinfo FW-FILE\n");
244 fprintf(stderr, "\nDescription:\n");
245 fprintf(stderr, "\tDisplay firmware descriptors information in "
246 "a human readable form.\n");
248 fprintf(stderr, "\nParameteres:\n");
249 fprintf(stderr, "\t 'FW-FILE' = firmware file/base-name\n\n");
252 int main(int argc, char *args[])
254 struct carlfw *fw = NULL;
255 struct carl9170fw_desc_head *fw_desc;
265 fw = carlfw_load(args[1]);
266 if (IS_ERR_OR_NULL(fw)) {
267 fprintf(stderr, "Failed to open firmware \"%s\" (%d).\n",
268 args[1], (int)PTR_ERR(fw));
272 carlfw_get_fw(fw, &len);
273 fprintf(stdout, "General Firmware Statistics:\n");
274 fprintf(stdout, "\tFirmware file size: %u Bytes\n", len);
275 fprintf(stdout, "\t%d Descriptors in %d Bytes\n",
276 carlfw_get_descs_num(fw), carlfw_get_descs_size(fw));
279 fprintf(stdout, "\nDetailed Descriptor Description:\n");
280 while ((fw_desc = carlfw_desc_next(fw, fw_desc))) {
281 show_desc_head(fw_desc);
283 for (i = 0; i < ARRAY_SIZE(known_magics); i++) {
284 if (carl9170fw_desc_cmp(fw_desc, known_magics[i].magic,
285 known_magics[i].size, known_magics[i].min_ver)) {
286 known_magics[i].func(fw_desc, fw);
291 if (i == ARRAY_SIZE(known_magics))
292 fprintf(stderr, "Unknown Descriptor.\n");
294 fprintf(stdout, "\n");
307 fprintf(stderr, "%s\n", strerror(-err));
312 return err ? EXIT_FAILURE : EXIT_SUCCESS;