2 * carlu - userspace testing utility for ar9170 devices
6 * Copyright 2009-2011 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>
43 void *carlu_alloc_driver(size_t size)
48 if (size < sizeof(*ar)) {
49 err("bogus driver context request.");
55 err("failed to alloc driver context.");
60 for (i = 0; i < __AR9170_NUM_TXQ; i++)
61 frame_queue_init(&ar->tx_sent_queue[i]);
62 ar->resp_lock = SDL_CreateMutex();
63 ar->mem_lock = SDL_CreateMutex();
64 ar->resp_pend = SDL_CreateCond();
69 void carlu_free_driver(struct carlu *ar)
73 dbg("destroy driver struct.\n");
74 SDL_DestroyMutex(ar->resp_lock);
75 SDL_DestroyMutex(ar->mem_lock);
76 SDL_DestroyCond(ar->resp_pend);
78 for (i = 0; i < __AR9170_NUM_TXQ; i++)
79 frame_queue_kill(&ar->tx_sent_queue[i]);
84 static int carlu_init()
86 struct SDL_version compiled;
89 SDL_VERSION(&compiled);
90 dbg("=== SDL %d.%d.%d ===\n", compiled.major, compiled.minor, compiled.patch);
92 ret = SDL_Init(SDL_INIT_TIMER);
94 err("Unable to initialize SDL: (%s)\n", SDL_GetError());
101 static void carlu_exit()
107 static int carlu_dump_eeprom(void)
109 struct carlu *carl = NULL;
110 uint8_t data[8192] = { 0 };
117 carl = carlusb_probe();
118 if (IS_ERR_OR_NULL(carl)) {
123 err = carlu_cmd_mem_dump(carl, 0, sizeof(data), &data);
127 print_hex_dump_bytes(INFO, "EEPROM:", data, sizeof(data));
134 return err ? EXIT_FAILURE : EXIT_SUCCESS;
137 static int carlu_run_gpio_test(void)
139 struct carlu *carl = NULL;
146 carl = carlusb_probe();
147 if (IS_ERR_OR_NULL(carl)) {
152 err = carlu_gpio_test(carl);
161 return err ? EXIT_FAILURE : EXIT_SUCCESS;
164 static int carlu_run_random_test(void)
166 struct carlu *carl = NULL;
173 carl = carlusb_probe();
174 if (IS_ERR_OR_NULL(carl)) {
179 err = carlu_random_test(carl);
188 return err ? EXIT_FAILURE : EXIT_SUCCESS;
191 static int carlu_run_loop_test(void)
200 carl = carlusb_probe();
201 if (IS_ERR_OR_NULL(carl)) {
206 carlu_cmd_write_mem(carl, AR9170_MAC_REG_BCN_PERIOD, 0xFFFFFFFF);
207 carlu_cmd_write_mem(carl, AR9170_MAC_REG_PRETBTT, 0xFFFFFFFF);
209 /* different payload test */
210 carlu_loopback_test(carl, 9000, 1000, 1566, 1566);
214 return err ? EXIT_FAILURE : EXIT_SUCCESS;
217 static int carlu_probe_all(void)
219 struct carlu *carl[32] = { 0 };
227 for (devs = 0; devs < ARRAY_SIZE(carl); devs++) {
228 carl[devs] = carlusb_probe();
229 if (IS_ERR_OR_NULL(carl[devs]))
233 info("Found %d devices\n", devs);
235 for (; devs > 0; devs--)
236 carlusb_close(carl[devs - 1]);
244 unsigned int parameters;
245 int (*function)(void);
249 #define MENU_ITEM(op, func, helpme) \
254 .help_text = helpme, \
257 static int show_help(void);
259 static const struct menu_struct menu[] = {
260 [0] = MENU_ITEM('h', show_help, "shows this useless help message text."), /* keep this entry at 0! */
261 MENU_ITEM('e', carlu_dump_eeprom, "hexdumps eeprom content to stdout."),
262 MENU_ITEM('l', carlusb_print_known_devices, "list of all known ar9170 usb devices."),
263 MENU_ITEM('p', carlu_probe_all, "probe all possible devices."),
264 MENU_ITEM('t', carlu_run_loop_test, "run tx/rx test."),
265 MENU_ITEM('g', carlu_run_gpio_test, "flash the leds."),
266 MENU_ITEM('r', carlu_run_random_test, "get random numbers."),
269 static int show_help(void)
272 char parameters[ARRAY_SIZE(menu) + 1];
274 for (i = 0; i < ARRAY_SIZE(menu); i++)
275 parameters[i] = menu[i].option;
277 parameters[ARRAY_SIZE(menu)] = '\0';
279 info("usage: ar9170user -[%s]\n", parameters);
281 for (i = 0; i < ARRAY_SIZE(menu); i++)
282 info("\t-%c\t%s\n", menu[i].option, menu[i].help_text);
287 static int select_menu_item(const char arg)
291 for (i = ARRAY_SIZE(menu) - 1; i != 0; i--) {
292 if (arg == menu[i].option)
296 return menu[i].function();
299 int main(int argc, char *argv[])
303 if (argc != 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
306 return select_menu_item(argv[1][1]);