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.
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 & 0xc0) != 0xc0) {
62 SDL_mutexP(ar->resp_lock);
63 if (ar->resp_buf && ar->resp_len && ar->resp_len >= (len - 4)) {
64 memcpy(ar->resp_buf, buf + 4, len - 4);
67 warn("spurious command response (%d / %d)\n",
68 (int) len - 4, (int) ar->resp_len);
69 print_hex_dump_bytes(WARNING, "RSP:", buf, len);
71 SDL_mutexV(ar->resp_lock);
73 SDL_CondSignal(ar->resp_pend);
78 ret = ar->cmd_cb(ar, cmd, buf, len);
81 switch (cmd->hdr.cmd) {
82 case CARL9170_RSP_TXCOMP:
83 carlu_tx_feedback(ar, cmd);
86 case CARL9170_RSP_TEXT:
87 info("carl9170 FW: %.*s\n", (int)len - 4, (char *)buf + 4);
90 case CARL9170_RSP_HEXDUMP:
91 info("carl9170 FW: hexdump\n");
92 print_hex_dump_bytes(INFO, "HEX:", (char *)buf + 4, len - 4);
95 case CARL9170_RSP_WATCHDOG:
96 err("Woof Woof! Watchdog notification.\n");
99 case CARL9170_RSP_GPIO:
100 info("GPIO Interrupt => GPIO state %.8x\n",
101 le32_to_cpu(cmd->gpio.gpio));
104 case CARL9170_RSP_RADAR:
105 info("RADAR Interrupt");
109 warn("received unhandled event 0x%x\n", cmd->hdr.cmd);
110 print_hex_dump_bytes(WARNING, "RSP:", (char *)buf + 4, len - 4);
116 static void __carlu_rx(struct carlu *ar, uint8_t *buf, unsigned int len)
122 /* weird thing, but this is the same in the original driver */
123 while (len > 2 && i < 12 && buf[0] == 0xff && buf[1] == 0xff) {
130 struct carl9170_rsp *cmd;
134 cmd = (void *) &buf[i];
136 carlu_handle_command(ar, cmd, cmd->hdr.len + 4);
137 i += cmd->hdr.len + 4;
140 carlu_handle_data(ar, buf, len);
144 static void carlu_rx_stream(struct carlu *ar, struct frame *frame)
146 void *buf = frame->data;
147 unsigned int len = frame->len;
150 struct ar9170_stream *rx_stream;
151 unsigned int resplen, elen;
153 rx_stream = (void *) buf;
154 resplen = le16_to_cpu(rx_stream->length);
155 elen = roundup(resplen + 4, 4);
157 if (rx_stream->tag != cpu_to_le16(0x4e00)) {
158 warn("frame has no tag %p %u %x.\n",
159 buf, (int) len, rx_stream->tag);
160 print_hex_dump_bytes(WARNING, "FRAME:", frame->data, frame->len);
162 __carlu_rx(ar, buf, len);
166 __carlu_rx(ar, rx_stream->payload, resplen);
173 void carlu_rx(struct carlu *ar, struct frame *frame)
176 carlu_rx_stream(ar, frame);
178 __carlu_rx(ar, frame->data, frame->len);