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.
38 #include "ieee80211.h"
41 static void carlu_handle_data(struct carlu *ar, void *buf,
45 ar->rx_cb(ar, buf, len);
47 dbg("unhandled data:\n");
48 print_hex_dump_bytes(VERBOSE, "DATA:", buf, len);
52 void carlu_handle_command(struct carlu *ar, void *buf,
55 struct carl9170_rsp *cmd;
60 if ((cmd->hdr.cmd & CARL9170_RSP_FLAG) != CARL9170_RSP_FLAG) {
61 if ((cmd->hdr.cmd & CARL9170_CMD_ASYNC_FLAG))
64 SDL_mutexP(ar->resp_lock);
65 if (ar->resp_buf && ar->resp_len && ar->resp_len >= (len - 4)) {
66 memcpy(ar->resp_buf, buf + 4, len - 4);
69 warn("spurious command response (%d / %d)\n",
70 (int) len - 4, (int) ar->resp_len);
71 print_hex_dump_bytes(WARNING, "RSP:", buf, len);
73 SDL_mutexV(ar->resp_lock);
75 SDL_CondSignal(ar->resp_pend);
80 ret = ar->cmd_cb(ar, cmd, buf, len);
83 switch (cmd->hdr.cmd) {
84 case CARL9170_RSP_TXCOMP:
85 carlu_tx_feedback(ar, cmd);
88 case CARL9170_RSP_TEXT:
89 info("carl9170 FW: %.*s\n", (int)len - 4, (char *)buf + 4);
92 case CARL9170_RSP_HEXDUMP:
93 info("carl9170 FW: hexdump\n");
94 print_hex_dump_bytes(INFO, "HEX:", (char *)buf + 4, len - 4);
97 case CARL9170_RSP_WATCHDOG:
98 err("Woof Woof! Watchdog notification.\n");
101 case CARL9170_RSP_GPIO:
102 info("GPIO Interrupt => GPIO state %.8x\n",
103 le32_to_cpu(cmd->gpio.gpio));
106 case CARL9170_RSP_RADAR:
107 info("RADAR Interrupt");
111 warn("received unhandled event 0x%x\n", cmd->hdr.cmd);
112 print_hex_dump_bytes(WARNING, "RSP:", (char *)buf + 4, len - 4);
118 static void __carlu_rx(struct carlu *ar, uint8_t *buf, unsigned int len)
124 /* weird thing, but this is the same in the original driver */
125 while (len > 2 && i < 12 && buf[0] == 0xff && buf[1] == 0xff) {
132 struct carl9170_rsp *cmd;
136 cmd = (void *) &buf[i];
138 carlu_handle_command(ar, cmd, cmd->hdr.len + 4);
139 i += cmd->hdr.len + 4;
142 carlu_handle_data(ar, buf, len);
146 static void carlu_rx_stream(struct carlu *ar, struct frame *frame)
148 void *buf = frame->data;
149 unsigned int len = frame->len;
152 struct ar9170_stream *rx_stream;
153 unsigned int resplen, elen;
155 rx_stream = (void *) buf;
156 resplen = le16_to_cpu(rx_stream->length);
157 elen = roundup(resplen + 4, 4);
159 if (rx_stream->tag != cpu_to_le16(0x4e00)) {
160 warn("frame has no tag %p %u %x.\n",
161 buf, (int) len, rx_stream->tag);
162 print_hex_dump_bytes(WARNING, "FRAME:", frame->data, frame->len);
164 __carlu_rx(ar, buf, len);
168 __carlu_rx(ar, rx_stream->payload, resplen);
175 void carlu_rx(struct carlu *ar, struct frame *frame)
178 carlu_rx_stream(ar, frame);
180 __carlu_rx(ar, frame->data, frame->len);