summaryrefslogtreecommitdiffstats
path: root/carl9170fw/tools/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:26:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:26:09 +0000
commit39a0d9019076a29a57a38a817b1830aef0708c11 (patch)
treed839d866a9986b99e90cd600f6874fae2f712be9 /carl9170fw/tools/src
parentInitial commit. (diff)
downloadfirmware-nonfree-upstream.tar.xz
firmware-nonfree-upstream.zip
Adding upstream version 20230210.upstream/20230210upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--carl9170fw/tools/src/CMakeLists.txt13
-rw-r--r--carl9170fw/tools/src/checksum.c89
-rw-r--r--carl9170fw/tools/src/eeprom_fix.c326
-rw-r--r--carl9170fw/tools/src/fwinfo.c331
-rw-r--r--carl9170fw/tools/src/miniboot.c200
-rw-r--r--carl9170fw/tools/src/wol.c209
6 files changed, 1168 insertions, 0 deletions
diff --git a/carl9170fw/tools/src/CMakeLists.txt b/carl9170fw/tools/src/CMakeLists.txt
new file mode 100644
index 0000000..3cd31fd
--- /dev/null
+++ b/carl9170fw/tools/src/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(tools)
+
+add_custom_target(wol ALL COMMAND gcc wol.c -o wol)
+
+set(tools fwinfo miniboot checksum eeprom_fix)
+
+foreach(tool ${tools})
+ add_executable( ${tool} ${tool}.c )
+ add_definitions("-std=gnu99 -Wall -Wextra -Wshadow")
+ target_link_libraries( ${tool} carlfw )
+endforeach()
diff --git a/carl9170fw/tools/src/checksum.c b/carl9170fw/tools/src/checksum.c
new file mode 100644
index 0000000..b394174
--- /dev/null
+++ b/carl9170fw/tools/src/checksum.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2010-2011 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "carlfw.h"
+
+#include "compiler.h"
+
+static void checksum_help(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\tchecksum FW-FILE\n");
+
+ fprintf(stderr, "\nDescription:\n");
+ fprintf(stderr, "\tThis simple utility adds/updates various "
+ "checksums.\n");
+
+ fprintf(stderr, "\nParameteres:\n");
+ fprintf(stderr, "\t 'FW-FILE' = firmware name\n");
+ fprintf(stderr, "\n");
+}
+
+int main(int argc, char *args[])
+{
+ struct carlfw *fw = NULL;
+ int err = 0;
+
+ if (argc != 2) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ fw = carlfw_load(args[1]);
+ if (IS_ERR_OR_NULL(fw)) {
+ err = PTR_ERR(fw);
+ fprintf(stderr, "Failed to open file \"%s\" (%d).\n",
+ args[1], err);
+ goto out;
+ }
+
+ /*
+ * No magic here, The checksum descriptor is added/update
+ * automatically in a subroutine of carlfw_store().
+ *
+ * This tools serves as a skeleton/example.
+ */
+ err = carlfw_store(fw);
+ if (err) {
+ fprintf(stderr, "Failed to apply checksum (%d).\n", err);
+ goto out;
+ }
+
+out:
+ switch (err) {
+ case 0:
+ fprintf(stdout, "checksum applied.\n");
+ break;
+ case -EINVAL:
+ checksum_help();
+ break;
+ default:
+ break;
+ }
+
+ carlfw_release(fw);
+ return err ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/carl9170fw/tools/src/eeprom_fix.c b/carl9170fw/tools/src/eeprom_fix.c
new file mode 100644
index 0000000..088510e
--- /dev/null
+++ b/carl9170fw/tools/src/eeprom_fix.c
@@ -0,0 +1,326 @@
+/*
+ * Copyright 2010-2011 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "carlfw.h"
+
+#include "compiler.h"
+
+static int get_val(char *str, unsigned int *val)
+{
+ int err;
+
+ err = sscanf(str, "%8x", val);
+ if (err != 1)
+ return -EINVAL;
+
+ return 0;
+}
+
+static int get_addr(char *str, unsigned int *val)
+{
+ int err;
+
+ err = get_val(str, val);
+ if (*val & 3) {
+ fprintf(stderr, "Address 0x%.8x is not a multiple of 4.\n",
+ *val);
+
+ return -EINVAL;
+ }
+
+ return err;
+}
+
+static int
+new_fix_entry(struct carlfw *fw, struct carl9170fw_fix_entry *fix_entry)
+{
+ struct carl9170fw_fix_desc *fix;
+ unsigned int len;
+
+ len = sizeof(*fix) + sizeof(*fix_entry);
+ fix = malloc(len);
+ if (!fix)
+ return -ENOMEM;
+
+ carl9170fw_fill_desc(&fix->head, (uint8_t *) FIX_MAGIC,
+ cpu_to_le16(len),
+ CARL9170FW_FIX_DESC_MIN_VER,
+ CARL9170FW_FIX_DESC_CUR_VER);
+
+ memcpy(&fix->data[0], fix_entry, sizeof(*fix_entry));
+
+ return carlfw_desc_add_tail(fw, &fix->head);
+}
+
+static struct carl9170fw_fix_entry *
+scan_for_similar_fix(struct carl9170fw_fix_desc *fix, __le32 address)
+{
+ unsigned int i, entries;
+
+ entries = (le16_to_cpu(fix->head.length) - sizeof(*fix)) /
+ sizeof(struct carl9170fw_fix_entry);
+
+ for (i = 0; i < entries; i++) {
+ if (address == fix->data[i].address)
+ return &fix->data[i];
+ }
+
+ return NULL;
+}
+
+static int
+add_another_fix_entry(struct carlfw *fw, struct carl9170fw_fix_desc *fix,
+ struct carl9170fw_fix_entry *fix_entry)
+{
+ unsigned int entry;
+
+ fix = carlfw_desc_mod_len(fw, &fix->head, sizeof(*fix_entry));
+ if (IS_ERR_OR_NULL(fix))
+ return (int) PTR_ERR(fix);
+
+ entry = (le16_to_cpu(fix->head.length) - sizeof(*fix)) /
+ sizeof(*fix_entry) - 1;
+
+ memcpy(&fix->data[entry], fix_entry, sizeof(*fix_entry));
+ return 0;
+}
+
+static int
+update_entry(char option, struct carl9170fw_fix_entry *entry,
+ struct carl9170fw_fix_entry *fix)
+{
+ switch (option) {
+ case '=':
+ entry->mask = fix->mask;
+ entry->value = fix->value;
+ break;
+
+ case 'O':
+ entry->mask |= fix->mask;
+ entry->value |= fix->value;
+ break;
+
+ case 'A':
+ entry->mask &= fix->mask;
+ entry->value &= fix->value;
+ break;
+
+ default:
+ fprintf(stderr, "Unknown option: '%c'\n", option);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void user_education(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\teeprom_fix FW-FILE SWITCH [ADDRESS [VALUE MASK]]\n");
+
+ fprintf(stderr, "\nDescription:\n");
+ fprintf(stderr, "\tThis utility manage a set of overrides which "
+ "commands the driver\n\tto load customized EEPROM' "
+ "data for all specified addresses.\n");
+
+ fprintf(stderr, "\nParameters:\n");
+ fprintf(stderr, "\t'FW-FILE' = firmware file [basename]\n");
+ fprintf(stderr, "\t'SWITCH' = [=|d|D]\n");
+ fprintf(stderr, "\t | '=' => add/set value for address\n");
+ fprintf(stderr, "\t | 'D' => removes all EEPROM overrides\n");
+ fprintf(stderr, "\t * 'd' => removed override for 'address'\n");
+ fprintf(stderr, "\n\t'ADDRESS' = location of the EEPROM override\n");
+ fprintf(stderr, "\t\t NB: must be a multiple of 4.\n");
+ fprintf(stderr, "\t\t an address map can be found in eeprom.h.\n");
+ fprintf(stderr, "\n\t'VALUE' = replacement value\n");
+ fprintf(stderr, "\t'MASK' = mask for the value placement.\n\n");
+
+ exit(EXIT_FAILURE);
+}
+
+static int
+set_fix(struct carlfw *fw, struct carl9170fw_fix_desc *fix,
+ char __unused option, int __unused argc, char *args[])
+{
+ struct carl9170fw_fix_entry fix_entry, *entry = NULL;
+ unsigned int address, value, mask;
+ int err;
+
+ err = get_addr(args[3], &address);
+ if (err)
+ return err;
+
+ err = get_val(args[4], &value);
+ if (err)
+ return err;
+
+ err = get_val(args[5], &mask);
+ if (err)
+ return err;
+
+ fix_entry.address = cpu_to_le32(address);
+ fix_entry.value = cpu_to_le32(value);
+ fix_entry.mask = cpu_to_le32(mask);
+
+ if (!fix) {
+ err = new_fix_entry(fw, &fix_entry);
+ } else {
+ entry = scan_for_similar_fix(fix, fix_entry.address);
+ if (entry) {
+ err = update_entry(option, entry, &fix_entry);
+ if (err)
+ fprintf(stdout, "Overwrite old entry.\n");
+ } else {
+ err = add_another_fix_entry(fw, fix, &fix_entry);
+ }
+ }
+
+ return err;
+}
+
+static int
+del_fix(struct carlfw *fw, struct carl9170fw_fix_desc *fix,
+ char __unused option, int __unused argc, char *args[])
+{
+ struct carl9170fw_fix_entry *entry = NULL;
+ unsigned int address;
+ unsigned long off;
+ unsigned int rem_len;
+ int err;
+
+ err = get_addr(args[3], &address);
+ if (err)
+ return err;
+
+ if (fix)
+ entry = scan_for_similar_fix(fix, cpu_to_le32(address));
+
+ if (!entry) {
+ fprintf(stderr, "Entry for 0x%.8x not found\n", address);
+ return -EINVAL;
+ }
+
+ off = (unsigned long) entry - (unsigned long) fix->data;
+ rem_len = le16_to_cpu(fix->head.length) - off;
+
+ if (rem_len) {
+ unsigned long cont;
+ cont = (unsigned long) entry + sizeof(*entry);
+ memmove(entry, (void *)cont, rem_len);
+ }
+
+ fix = carlfw_desc_mod_len(fw, &fix->head, -sizeof(*entry));
+ err = IS_ERR_OR_NULL(fix);
+ return err;
+}
+
+static int del_all(struct carlfw *fw, struct carl9170fw_fix_desc *fix,
+ char __unused option, int __unused argc, char __unused *args[])
+{
+ if (!fix)
+ return 0;
+
+ carlfw_desc_del(fw, &fix->head);
+ return 0;
+}
+
+static const struct {
+ char option;
+ int argc;
+ int (*func)(struct carlfw *, struct carl9170fw_fix_desc *,
+ char, int, char **);
+} programm_function[] = {
+ { '=', 6, set_fix },
+ { 'O', 6, set_fix },
+ { 'A', 6, set_fix },
+ { 'd', 4, del_fix },
+ { 'D', 3, del_all },
+};
+
+int main(int argc, char *args[])
+{
+ struct carl9170fw_fix_desc *fix;
+ struct carlfw *fw = NULL;
+ unsigned int i;
+ int err = 0;
+ char option;
+
+ if (argc < 3 || argc > 6) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ fw = carlfw_load(args[1]);
+ if (IS_ERR_OR_NULL(fw)) {
+ err = PTR_ERR(fw);
+ fprintf(stderr, "Failed to open file \"%s\" (%d).\n",
+ args[1], err);
+ goto out;
+ }
+
+ fix = carlfw_find_desc(fw, (uint8_t *)FIX_MAGIC, sizeof(*fix),
+ CARL9170FW_FIX_DESC_CUR_VER);
+
+ option = args[2][0];
+ for (i = 0; i < ARRAY_SIZE(programm_function); i++) {
+ if (programm_function[i].option != option)
+ continue;
+
+ if (argc != programm_function[i].argc) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ err = programm_function[i].func(fw, fix, option, argc, args);
+ if (err)
+ goto out;
+
+ break;
+ }
+ if (i == ARRAY_SIZE(programm_function)) {
+ fprintf(stderr, "Unknown option: '%c'\n",
+ args[2][0]);
+ goto out;
+ }
+
+ err = carlfw_store(fw);
+ if (err) {
+ fprintf(stderr, "Failed to apply changes (%d).\n", err);
+ goto out;
+ }
+
+out:
+ carlfw_release(fw);
+
+ if (err) {
+ if (err == -EINVAL)
+ user_education();
+ else
+ fprintf(stderr, "%s\n", strerror(err));
+ }
+
+ return err ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/carl9170fw/tools/src/fwinfo.c b/carl9170fw/tools/src/fwinfo.c
new file mode 100644
index 0000000..0d5cd09
--- /dev/null
+++ b/carl9170fw/tools/src/fwinfo.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright 2010-2011 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "carlfw.h"
+
+#include "fwcmd.h"
+#include "compiler.h"
+
+struct feature_list {
+ unsigned int id;
+ char name[64];
+ void (*func)(const struct carl9170fw_desc_head *, struct carlfw *fw);
+};
+
+#define CHECK_FOR_FEATURE(feature_enum) \
+ { .id = feature_enum, .name = #feature_enum, .func = NULL }
+
+#define CHECK_FOR_FEATURE_FUNC(feature_enum, _func) \
+ { .id = feature_enum, .name = #feature_enum, .func = _func }
+
+static void show_miniboot_info(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_otus_desc *otus = (const void *) head;
+
+ fprintf(stdout, "\t\t\tminiboot size: %d Bytes\n", otus->miniboot_size);
+}
+
+static const struct feature_list known_otus_features_v1[] = {
+ CHECK_FOR_FEATURE(CARL9170FW_DUMMY_FEATURE),
+ CHECK_FOR_FEATURE_FUNC(CARL9170FW_MINIBOOT, show_miniboot_info),
+ CHECK_FOR_FEATURE(CARL9170FW_USB_INIT_FIRMWARE),
+ CHECK_FOR_FEATURE(CARL9170FW_USB_RESP_EP2),
+ CHECK_FOR_FEATURE(CARL9170FW_USB_DOWN_STREAM),
+ CHECK_FOR_FEATURE(CARL9170FW_USB_UP_STREAM),
+ CHECK_FOR_FEATURE(CARL9170FW_UNUSABLE),
+ CHECK_FOR_FEATURE(CARL9170FW_COMMAND_PHY),
+ CHECK_FOR_FEATURE(CARL9170FW_COMMAND_CAM),
+ CHECK_FOR_FEATURE(CARL9170FW_WLANTX_CAB),
+ CHECK_FOR_FEATURE(CARL9170FW_HANDLE_BACK_REQ),
+ CHECK_FOR_FEATURE(CARL9170FW_GPIO_INTERRUPT),
+ CHECK_FOR_FEATURE(CARL9170FW_PSM),
+ CHECK_FOR_FEATURE(CARL9170FW_RX_FILTER),
+ CHECK_FOR_FEATURE(CARL9170FW_WOL),
+ CHECK_FOR_FEATURE(CARL9170FW_FIXED_5GHZ_PSM),
+ CHECK_FOR_FEATURE(CARL9170FW_HW_COUNTERS),
+ CHECK_FOR_FEATURE(CARL9170FW_RX_BA_FILTER),
+};
+
+static void check_feature_list(const struct carl9170fw_desc_head *head,
+ const __le32 bitmap,
+ const struct feature_list *list,
+ const unsigned int entries,
+ struct carlfw *fw)
+{
+ unsigned int i;
+
+ for (i = 0; i < entries; i++) {
+ if (!carl9170fw_supports(bitmap, list[i].id))
+ continue;
+
+ fprintf(stdout, "\t\t%2d = %s\n", list[i].id, list[i].name);
+ if (list[i].func)
+ list[i].func(head, fw);
+ }
+}
+
+static void show_otus_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw)
+{
+ const struct carl9170fw_otus_desc *otus = (const void *) head;
+
+ BUILD_BUG_ON(ARRAY_SIZE(known_otus_features_v1) != __CARL9170FW_FEATURE_NUM);
+
+ fprintf(stdout, "\tFirmware upload pointer: 0x%x\n",
+ otus->fw_address);
+ fprintf(stdout, "\tBeacon Address: %x, (reserved:%d Bytes)\n",
+ le32_to_cpu(otus->bcn_addr), le16_to_cpu(otus->bcn_len));
+ fprintf(stdout, "\tTX DMA chunk size:%d Bytes, TX DMA chunks:%d\n",
+ otus->tx_frag_len, otus->tx_descs);
+ fprintf(stdout, "\t=> %d Bytes are reserved for the TX queues\n",
+ otus->tx_frag_len * otus->tx_descs);
+ fprintf(stdout, "\tCommand response buffers:%d\n", otus->cmd_bufs);
+ fprintf(stdout, "\tMax. RX stream block size:%d Bytes\n",
+ otus->rx_max_frame_len);
+ fprintf(stdout, "\tSupported Firmware Interfaces: %d\n", otus->vif_num);
+ fprintf(stdout, "\tFirmware API Version: %d\n", otus->api_ver);
+ fprintf(stdout, "\tSupported Features: (raw:%.08x)\n",
+ le32_to_cpu(otus->feature_set));
+
+ check_feature_list(head, otus->feature_set, known_otus_features_v1,
+ ARRAY_SIZE(known_otus_features_v1), fw);
+}
+
+static void show_motd_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_motd_desc *motd = (const void *) head;
+ char buf[CARL9170FW_MOTD_STRING_LEN];
+ unsigned int fw_date;
+
+ fw_date = motd->fw_year_month_day;
+ fprintf(stdout, "\tFirmware Build Date (YYYY-MM-DD): 2%03d-%02d-%02d\n",
+ CARL9170FW_GET_YEAR(fw_date), CARL9170FW_GET_MONTH(fw_date),
+ CARL9170FW_GET_DAY(fw_date));
+
+ strncpy(buf, motd->desc, CARL9170FW_MOTD_STRING_LEN);
+ fprintf(stdout, "\tFirmware Text:\"%s\"\n", buf);
+
+ strncpy(buf, motd->release, CARL9170FW_MOTD_STRING_LEN);
+ fprintf(stdout, "\tFirmware Release:\"%s\"\n", buf);
+}
+
+static void show_fix_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_fix_desc *fix = (const void *) head;
+ const struct carl9170fw_fix_entry *iter;
+ unsigned int i;
+
+ for (i = 0; i < (head->length - sizeof(*head)) / sizeof(*iter); i++) {
+ iter = &fix->data[i];
+ fprintf(stdout, "\t\t%d: 0x%.8x := 0x%.8x (0x%.8x)\n", i,
+ le32_to_cpu(iter->address), le32_to_cpu(iter->value),
+ le32_to_cpu(iter->mask));
+ }
+}
+
+static void show_dbg_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_dbg_desc *dbg = (const void *) head;
+
+#define DBG_ADDR(_name, _reg) do { \
+ unsigned int __tmp = le32_to_cpu(dbg->_reg); \
+ if (__tmp) \
+ fprintf(stdout, "\t\t" _name " = 0x%.8x\n", __tmp); \
+ } while (0);
+
+ fprintf(stdout, "\tFirmware Debug Registers/Counters\n");
+ DBG_ADDR("bogoclock ", bogoclock_addr);
+ DBG_ADDR("counter ", counter_addr);
+ DBG_ADDR("rx total ", rx_total_addr);
+ DBG_ADDR("rx overrun ", rx_overrun_addr);
+ DBG_ADDR("rx filer ", rx_filter);
+}
+
+static void show_txsq_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_txsq_desc *txsq = (const void *) head;
+
+ fprintf(stdout, "\t\ttx-seq table addr: 0x%x\n",
+ le32_to_cpu(txsq->seq_table_addr));
+}
+
+
+static const struct feature_list wol_triggers_v1[] = {
+ CHECK_FOR_FEATURE(CARL9170_WOL_DISCONNECT),
+ CHECK_FOR_FEATURE(CARL9170_WOL_MAGIC_PKT),
+};
+
+static void show_wol_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_wol_desc *wol = (const void *) head;
+
+ fprintf(stdout, "\tSupported WOWLAN triggers: (raw:%.08x)\n",
+ le32_to_cpu(wol->supported_triggers));
+
+ check_feature_list(head, wol->supported_triggers, wol_triggers_v1,
+ ARRAY_SIZE(wol_triggers_v1), fw);
+}
+
+static void show_chk_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+{
+ const struct carl9170fw_chk_desc *chk = (const void *) head;
+
+ fprintf(stdout, "\tFirmware Descriptor CRC32: %08x\n",
+ le32_to_cpu(chk->hdr_crc32));
+ fprintf(stdout, "\tFirmware Image CRC32: %08x\n",
+ le32_to_cpu(chk->fw_crc32));
+}
+
+static void show_last_desc(const struct carl9170fw_desc_head *head,
+ struct carlfw *fw __unused)
+
+{
+ const struct carl9170fw_last_desc *last __unused = (const void *) head;
+
+ /* Nothing here */
+}
+
+#define ADD_HANDLER(_magic, _func) \
+ { \
+ .magic = _magic##_MAGIC, \
+ .min_ver = CARL9170FW_## _magic##_DESC_CUR_VER, \
+ .func = _func, \
+ .size = CARL9170FW_## _magic##_DESC_SIZE, \
+ }
+
+static const struct {
+ uint8_t magic[4];
+ uint8_t min_ver;
+ void (*func)(const struct carl9170fw_desc_head *, struct carlfw *);
+ uint16_t size;
+} known_magics[] = {
+ ADD_HANDLER(OTUS, show_otus_desc),
+ ADD_HANDLER(TXSQ, show_txsq_desc),
+ ADD_HANDLER(MOTD, show_motd_desc),
+ ADD_HANDLER(DBG, show_dbg_desc),
+ ADD_HANDLER(FIX, show_fix_desc),
+ ADD_HANDLER(CHK, show_chk_desc),
+ ADD_HANDLER(WOL, show_wol_desc),
+ ADD_HANDLER(LAST, show_last_desc),
+};
+
+static const uint8_t otus_magic[4] = { OTUS_MAGIC };
+
+static void show_desc_head(struct carl9170fw_desc_head *head)
+{
+#define P(c) (isprint(c) ? c : ' ')
+
+ fprintf(stdout, ">\t%c%c%c%c Descriptor: size:%d, compatible:%d, "
+ "version:%d\n",
+ P(head->magic[0]), P(head->magic[1]), P(head->magic[2]),
+ P(head->magic[3]), le16_to_cpu(head->length), head->min_ver,
+ head->cur_ver);
+}
+
+static void fwinfo_info(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\tfwinfo FW-FILE\n");
+
+ fprintf(stderr, "\nDescription:\n");
+ fprintf(stderr, "\tDisplay firmware descriptors information in "
+ "a human readable form.\n");
+
+ fprintf(stderr, "\nParameteres:\n");
+ fprintf(stderr, "\t 'FW-FILE' = firmware file/base-name\n\n");
+}
+
+int main(int argc, char *args[])
+{
+ struct carlfw *fw = NULL;
+ struct carl9170fw_desc_head *fw_desc;
+ unsigned int i;
+ int err = 0;
+ size_t len;
+
+ if (argc != 2) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ fw = carlfw_load(args[1]);
+ if (IS_ERR_OR_NULL(fw)) {
+ err = PTR_ERR(fw);
+ fprintf(stderr, "Failed to open firmware \"%s\" (%d).\n",
+ args[1], err);
+ goto out;
+ }
+
+ carlfw_get_fw(fw, &len);
+ fprintf(stdout, "General Firmware Statistics:\n");
+ fprintf(stdout, "\tFirmware file size: %u Bytes\n", (unsigned int)len);
+ fprintf(stdout, "\t%d Descriptors in %d Bytes\n",
+ carlfw_get_descs_num(fw), carlfw_get_descs_size(fw));
+
+ fw_desc = NULL;
+ fprintf(stdout, "\nDetailed Descriptor Description:\n");
+ while ((fw_desc = carlfw_desc_next(fw, fw_desc))) {
+ show_desc_head(fw_desc);
+
+ for (i = 0; i < ARRAY_SIZE(known_magics); i++) {
+ if (carl9170fw_desc_cmp(fw_desc, known_magics[i].magic,
+ known_magics[i].size, known_magics[i].min_ver)) {
+ known_magics[i].func(fw_desc, fw);
+ break;
+ }
+ }
+
+ if (i == ARRAY_SIZE(known_magics))
+ fprintf(stderr, "Unknown Descriptor.\n");
+
+ fprintf(stdout, "\n");
+ }
+
+out:
+ switch (err) {
+ case 0:
+ break;
+
+ case -EINVAL:
+ fwinfo_info();
+ break;
+
+ default:
+ fprintf(stderr, "%s\n", strerror(-err));
+ break;
+ }
+
+ carlfw_release(fw);
+ return err ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/carl9170fw/tools/src/miniboot.c b/carl9170fw/tools/src/miniboot.c
new file mode 100644
index 0000000..509d82d
--- /dev/null
+++ b/carl9170fw/tools/src/miniboot.c
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2010-2011 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "carlfw.h"
+
+#include "compiler.h"
+
+static void mini_help(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\tminiboot ACTION FW-FILE [MB-FILE]\n");
+
+ fprintf(stderr, "\nDescription:\n");
+ fprintf(stderr, "\tFirmware concatenation utility.\n");
+
+ fprintf(stderr, "\nParameteres:\n");
+ fprintf(stderr, "\t'ACTION' = [a|d]\n");
+ fprintf(stderr, "\t | 'a' = Add miniboot firmware.\n");
+ fprintf(stderr, "\t * 'd' = remove miniboot firmware.\n");
+ fprintf(stderr, "\t'FW-FILE' = destination for the package.\n");
+ fprintf(stderr, "\t'MB-FILE' = extra firmware image.\n");
+}
+
+static int add_mini(struct carlfw *fw, const char *mini)
+{
+ struct stat file_stat;
+ struct carl9170fw_otus_desc *otus_desc = NULL;
+ FILE *m = NULL;
+ char *buf = NULL;
+ size_t extra;
+ int err;
+
+ m = fopen(mini, "r");
+ if (m == NULL) {
+ fprintf(stderr, "Failed to open file %s (%d).\n",
+ mini, errno);
+ err = -errno;
+ goto fail;
+ }
+
+ err = fstat(fileno(m), &file_stat);
+ if (err) {
+ fprintf(stderr, "Failed to query file infos from "
+ "\"%s\" (%d).\n", mini, errno);
+ err = -errno;
+ goto fail;
+ }
+ extra = file_stat.st_size;
+
+ otus_desc = carlfw_find_desc(fw, (uint8_t *) OTUS_MAGIC,
+ sizeof(*otus_desc),
+ CARL9170FW_OTUS_DESC_CUR_VER);
+ if (!otus_desc) {
+ fprintf(stderr, "No OTUS descriptor found\n");
+ goto fail;
+ }
+
+ if (carl9170fw_supports(otus_desc->feature_set, CARL9170FW_MINIBOOT)) {
+ fprintf(stderr, "Firmware has already a miniboot image.\n");
+ goto fail;
+ }
+
+ otus_desc->feature_set |= cpu_to_le32(BIT(CARL9170FW_MINIBOOT));
+ otus_desc->miniboot_size = cpu_to_le16(extra);
+
+ buf = carlfw_mod_headroom(fw, extra);
+ if (IS_ERR_OR_NULL(buf)) {
+ fprintf(stderr, "Unable to add miniboot image.\n");
+ goto fail;
+ }
+
+ err = fread(buf, extra, 1, m);
+ if (err != 1) {
+ fprintf(stderr, "Unable to load miniboot.\n");
+ goto fail;
+ }
+
+ carlfw_store(fw);
+ fclose(m);
+
+ return 0;
+
+fail:
+ if (m)
+ fclose(m);
+
+ return err;
+}
+
+static int del_mini(struct carlfw *fw)
+{
+ struct carl9170fw_otus_desc *otus_desc = NULL;
+ void *buf;
+ int cut;
+
+ otus_desc = carlfw_find_desc(fw, (uint8_t *) OTUS_MAGIC,
+ sizeof(*otus_desc),
+ CARL9170FW_OTUS_DESC_CUR_VER);
+ if (!otus_desc) {
+ fprintf(stderr, "Firmware is not for USB devices.\n");
+ return -ENODATA;
+ }
+
+ if (!carl9170fw_supports(otus_desc->feature_set, CARL9170FW_MINIBOOT)) {
+ fprintf(stderr, "Firmware has no miniboot image.\n");
+ return -EINVAL;
+ }
+
+ cut = le16_to_cpu(otus_desc->miniboot_size);
+
+ buf = carlfw_mod_headroom(fw, -cut);
+ if (IS_ERR_OR_NULL(buf)) {
+ fprintf(stderr, "Unable to remove miniboot.\n");
+ return PTR_ERR(buf);
+ }
+
+ otus_desc->feature_set &= cpu_to_le32(~BIT(CARL9170FW_MINIBOOT));
+ otus_desc->miniboot_size = cpu_to_le16(0);
+
+ carlfw_store(fw);
+ return 0;
+}
+
+int main(int argc, char *args[])
+{
+ struct carlfw *fw = NULL;
+ int err;
+
+ if (argc < 3 || argc > 4) {
+ err = -EINVAL;
+ goto err_param;
+ }
+
+ switch (args[1][0]) {
+ case 'a':
+ if (argc != 4)
+ goto err_param;
+
+ fw = carlfw_load(args[2]);
+ if (IS_ERR_OR_NULL(fw)) {
+ err = PTR_ERR(fw);
+ goto err_out;
+ }
+
+ err = add_mini(fw, args[3]);
+ break;
+ case 'd':
+ if (argc != 3)
+ goto err_param;
+
+ fw = carlfw_load(args[2]);
+ if (IS_ERR_OR_NULL(fw)) {
+ err = PTR_ERR(fw);
+ goto err_out;
+ }
+
+ err = del_mini(fw);
+ break;
+
+ default:
+ goto err_param;
+ break;
+ }
+
+ carlfw_release(fw);
+ return EXIT_SUCCESS;
+
+err_out:
+ carlfw_release(fw);
+ fprintf(stderr, "miniboot action failed (%d).\n", err);
+ return EXIT_FAILURE;
+
+err_param:
+ carlfw_release(fw);
+ mini_help();
+ return EXIT_FAILURE;
+}
diff --git a/carl9170fw/tools/src/wol.c b/carl9170fw/tools/src/wol.c
new file mode 100644
index 0000000..41daba2
--- /dev/null
+++ b/carl9170fw/tools/src/wol.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2011, Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <linux/types.h>
+#include <linux/if_ether.h> /* ETH_P_ALL */
+#include <linux/if_packet.h> /* sockaddr_ll */
+#include <linux/if.h> /* IFNAMSIZ */
+
+static int monitor_init(const char *ifname)
+{
+ struct sockaddr_ll ll;
+ int monitor_sock;
+
+ memset(&ll, 0, sizeof(ll));
+ ll.sll_family = AF_PACKET;
+ ll.sll_ifindex = if_nametoindex(ifname);
+ if (ll.sll_ifindex == 0) {
+ fprintf(stderr, "Monitor interface '%s' does not exist\n", ifname);
+ return -1;
+ }
+
+ monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if (monitor_sock < 0) {
+ fprintf(stderr, "socket(PF_PACKET,SOCK_RAW): %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (bind(monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
+ fprintf(stderr, "bind(PACKET): %s\n", strerror(errno));
+ close(monitor_sock);
+ return -1;
+ }
+
+ return monitor_sock;
+}
+
+static int inject_frame(int s, const void *data, size_t len)
+{
+#define IEEE80211_RADIOTAP_F_FRAG 0x08
+ unsigned char rtap_hdr[] = {
+ 0x00, 0x00, /* radiotap version */
+ 0x0e, 0x00, /* radiotap length */
+ 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
+ IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
+ 0x00, /* padding */
+ 0x00, 0x00, /* RX and TX flags to indicate that */
+ 0x00, 0x00, /* this is the injected frame directly */
+ };
+ struct iovec iov[2] = {
+ {
+ .iov_base = &rtap_hdr,
+ .iov_len = sizeof(rtap_hdr),
+ },
+ {
+ .iov_base = (void *) data,
+ .iov_len = len,
+ }
+ };
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = iov,
+ .msg_iovlen = 2,
+ .msg_control = NULL,
+ .msg_controllen = 0,
+ .msg_flags = 0,
+ };
+ int ret;
+
+ ret = sendmsg(s, &msg, 0);
+ if (ret < 0)
+ perror("sendmsg");
+ return ret;
+}
+
+static unsigned char wol_magic_tmpl[30 + 6 + 16 * 6] = {
+ 0x08, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* RA */
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* TA */
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* SA */
+ 0x00, 0x00,
+
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+
+static void prepare_wol(unsigned char *wol_magic, unsigned char *mac)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ memcpy(&wol_magic[30 + i * 6], mac, 6);
+}
+
+void usage(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\twol -i monitor_dev -m DE:VI:CE:MA:CW:OL -n #num -v\n");
+
+ fprintf(stderr, "\nDescription:\n");
+ fprintf(stderr, "\tThis utility generates a WOL packet for the"
+ "given [MAC] address and tries to injects"
+ "it into [monitor_dev]\n");
+
+ exit(EXIT_FAILURE);
+}
+
+#define MAC_STR "%2X:%2X:%2X:%2X:%2X:%2X"
+
+#define M(a, i) ((unsigned int *)&a[i])
+#define MAC_ARG(a) M(a, 0), M(a, 1), M(a, 2), M(a, 3), M(a, 4), M(a, 5)
+
+#define M2(a, i) (a[i])
+#define MAC_ARG2(a) M2(a, 0), M2(a, 1), M2(a, 2), M2(a, 3), M2(a, 4), M2(a, 5)
+
+int main(int argc, char **args)
+{
+ int sock, err = 0, opt, num = 10;
+ unsigned char mac[ETH_ALEN];
+ char dev_name[IFNAMSIZ + 1] = { 0 };
+ bool has_mac = false, has_dev = false, verbose = false;
+
+ while ((opt = getopt(argc, args, "m:i:n:v")) != -EXIT_FAILURE) {
+ switch (opt) {
+ case 'i':
+ has_dev = true;
+ strncpy(dev_name, optarg, IFNAMSIZ);
+ break;
+ case 'm':
+ has_mac = true;
+ err = sscanf(optarg, MAC_STR, MAC_ARG(mac)) != 6;
+ if (err)
+ fprintf(stderr, "invalid MAC: \"%s\"\n", optarg);
+ break;
+
+ case 'n':
+ err = sscanf(optarg, "%d", &num) != 1;
+ err |= num < 1 | num > 1000;
+ if (err)
+ fprintf(stderr, "invalid tries: \"%s\"\n", optarg);
+ break;
+
+ case 'v':
+ verbose = true;
+ break;
+
+ default:
+ err = -EINVAL;
+ break;
+ }
+
+ if (err)
+ break;
+ }
+
+ if (!has_mac || !has_dev || err)
+ usage();
+
+ if (verbose)
+ fprintf(stdout, "Opening monitor injection interface [%s].\n", dev_name);
+
+ sock = monitor_init(dev_name);
+ if (sock < 0)
+ return EXIT_FAILURE;
+
+ if (verbose)
+ fprintf(stdout, "Generating %d WOL packet for ["MAC_STR"].\n", num, MAC_ARG2(mac));
+
+ prepare_wol(wol_magic_tmpl, mac);
+
+ while (num--) {
+ err = inject_frame(sock, wol_magic_tmpl, sizeof(wol_magic_tmpl));
+ if (err < 0) {
+ fprintf(stderr, "failed to send WOL packet.\n");
+ break;
+ } else if (verbose) {
+ fprintf(stdout, "WOL packet sent.\n");
+ }
+ }
+
+ close(sock);
+ if (err < 0)
+ return EXIT_FAILURE;
+
+ return 0;
+}