2 * carl9170user - userspace testing utility for ar9170 devices
6 * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include <SDL_version.h>
42 void *carlu_alloc_driver(size_t size)
47 if (size < sizeof(*ar)) {
48 err("bogus driver context request.");
54 err("failed to alloc driver context.");
59 for (i = 0; i < __AR9170_NUM_TXQ; i++)
60 frame_queue_init(&ar->tx_sent_queue[i]);
61 ar->resp_lock = SDL_CreateMutex();
62 ar->mem_lock = SDL_CreateMutex();
63 ar->resp_pend = SDL_CreateCond();
68 void carlu_free_driver(struct carlu *ar)
72 dbg("destroy driver struct.\n");
73 SDL_DestroyMutex(ar->resp_lock);
74 SDL_DestroyMutex(ar->mem_lock);
75 SDL_DestroyCond(ar->resp_pend);
77 for (i = 0; i < __AR9170_NUM_TXQ; i++)
78 frame_queue_kill(&ar->tx_sent_queue[i]);
83 static int carlu_init()
85 struct SDL_version compiled;
88 SDL_VERSION(&compiled);
89 dbg("=== SDL %d.%d.%d ===\n", compiled.major, compiled.minor, compiled.patch);
91 ret = SDL_Init(SDL_INIT_TIMER);
93 err("Unable to initialize SDL: (%s)\n", SDL_GetError());
100 static void carlu_exit()
106 static int carlu_dump_eeprom(void)
108 struct carlu *carl = NULL;
109 uint8_t data[8192] = { 0 };
116 carl = carlusb_probe();
117 if (IS_ERR_OR_NULL(carl)) {
122 err = carlu_cmd_mem_dump(carl, 0, sizeof(data), &data);
126 print_hex_dump_bytes(INFO, "EEPROM:", data, sizeof(data));
133 return err ? EXIT_FAILURE : EXIT_SUCCESS;
136 static int carlu_run_loop_test(void)
145 carl = carlusb_probe();
146 if (IS_ERR_OR_NULL(carl)) {
151 carlu_cmd_write_mem(carl, AR9170_MAC_REG_BCN_PERIOD, 0xFFFFFFFF);
152 carlu_cmd_write_mem(carl, AR9170_MAC_REG_PRETBTT, 0xFFFFFFFF);
154 /* different payload test */
155 carlu_loopback_test(carl, 9000, 1000, 1566, 1566);
159 return err ? EXIT_FAILURE : EXIT_SUCCESS;
162 static int carlu_probe_all(void)
164 struct carlu *carl[32] = { 0 };
172 for (devs = 0; devs < ARRAY_SIZE(carl); devs++) {
173 carl[devs] = carlusb_probe();
174 if (IS_ERR_OR_NULL(carl[devs]))
178 info("Found %d devices\n", devs);
180 for (; devs > 0; devs--)
181 carlusb_close(carl[devs - 1]);
189 unsigned int parameters;
190 int (*function)(void);
194 #define MENU_ITEM(op, func, helpme) \
199 .help_text = helpme, \
202 static int show_help(void);
204 static const struct menu_struct menu[] = {
205 [0] = MENU_ITEM('h', show_help, "shows this useless help message text."), /* keep this entry at 0! */
206 MENU_ITEM('e', carlu_dump_eeprom, "hexdumps eeprom content to stdout."),
207 MENU_ITEM('l', carlusb_print_known_devices, "list of all known ar9170 usb devices."),
208 MENU_ITEM('p', carlu_probe_all, "probe all possible devices."),
209 MENU_ITEM('t', carlu_run_loop_test, "run tx/rx test."),
212 static int show_help(void)
215 char parameters[ARRAY_SIZE(menu) + 1];
217 for (i = 0; i < ARRAY_SIZE(menu); i++)
218 parameters[i] = menu[i].option;
220 parameters[ARRAY_SIZE(menu)] = '\0';
222 info("usage: ar9170user -[%s]\n", parameters);
224 for (i = 0; i < ARRAY_SIZE(menu); i++)
225 info("\t-%c\t%s\n", menu[i].option, menu[i].help_text);
230 static int select_menu_item(const char arg)
234 for (i = ARRAY_SIZE(menu) - 1; i != 0; i--) {
235 if (arg == menu[i].option)
239 return menu[i].function();
242 int main(int argc, char *argv[])
246 if (argc != 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
249 return select_menu_item(argv[1][1]);