Date:2011-07-12 17:10:48 (9 years 1 month ago)
Author:Werner Almesberger
Commit:49d6067e887e91038e83ade0233eba7e0d99ecdb
Message:tools/lib/: added HardMAC functions to the atusb drivers

Files: tools/lib/atusb-common.c (2 diffs)
tools/lib/atusb-common.h (1 diff)
tools/lib/atusb-spi.c (1 diff)
tools/lib/atusb.c (1 diff)

Change Details

tools/lib/atusb-common.c
1414#include <stdint.h>
1515#include <stdlib.h>
1616#include <stdio.h>
17#include <string.h>
1718#include <usb.h>
1819#include <errno.h>
1920
...... 
276277}
277278
278279
280/* ----- HardMAC ----------------------------------------------------------- */
281
282
283void atusb_rx_mode(void *handle, int on)
284{
285    struct atusb_dsc *dsc = handle;
286    int res;
287
288    if (dsc->error)
289        return;
290
291    res = usb_control_msg(dsc->dev, TO_DEV, ATUSB_RX_MODE,
292        on, 0, NULL, 0, 1000);
293    if (res < 0) {
294        fprintf(stderr, "ATUSB_RX_MODE: %d\n", res);
295        dsc->error = 1;
296    }
297}
298
299
300int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi)
301{
302    struct atusb_dsc *dsc = handle;
303    uint8_t len;
304    int res;
305    uint8_t tmp[MAX_PSDU+2]; /* PHR, LQI */
306
307    /*
308     * Seems that either the USB stack of libusb doesn't like it if we do a
309     * read of size one followed by the full read. Therefore, we just do
310     * a maximum-sized read and hope that we don't split packets.
311     */
312    res = usb_bulk_read(dsc->dev, 1, (char *) tmp, sizeof(tmp), 0);
313    if (res < 0) {
314        fprintf(stderr, "usb_bulk_read: %d\n", res);
315        dsc->error = 1;
316        return 0;
317    }
318
319    len = tmp[0];
320    if (len & 0x80) {
321        fprintf(stderr, "atusb_rx: invalid length 0x%02x\n", len);
322        return 0;
323    }
324    if (len > size) {
325        fprintf(stderr, "atusb_rx: len %u > size %d\n", len, size);
326        return 0;
327    }
328    if (len > res+2) {
329        fprintf(stderr, "atusb_rx: len %u > res %d+2\n", len, res);
330        return 0;
331    }
332
333    memcpy(buf, tmp+1, len);
334    if (lqi)
335        *lqi = tmp[len+1];
336
337    return len;
338}
339
340
341void atusb_tx(void *handle, const void *buf, int size)
342{
343    struct atusb_dsc *dsc = handle;
344    int res;
345
346    if (dsc->error)
347        return;
348
349    res = usb_control_msg(dsc->dev, TO_DEV, ATUSB_TX,
350        0, 0, (void *) buf, size, 1000);
351    if (res < 0) {
352        fprintf(stderr, "ATUSB_TX: %d\n", res);
353        dsc->error = 1;
354    }
355}
356
357
279358/* ----- Driver-specific hacks --------------------------------------------- */
280359
281360
tools/lib/atusb-common.h
3434void atusb_test_mode(void *handle);
3535void atusb_slp_tr(void *handle, int on, int pulse);
3636int atusb_interrupt_wait(void *handle, int timeout_ms);
37void atusb_rx_mode(void *handle, int on);
38int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi);
39void atusb_tx(void *handle, const void *buf, int size);
3740
3841int atusb_set_clkm(void *handle, int mhz);
3942
tools/lib/atusb-spi.c
168168    .sram_write = atusb_spi_sram_write,
169169    .sram_read = atusb_spi_sram_read,
170170    .interrupt_wait = atusb_interrupt_wait,
171    .rx_mode = atusb_rx_mode,
172    .rx = atusb_rx,
173    .tx = atusb_tx,
171174};
tools/lib/atusb.c
162162    .sram_write = atusb_sram_write,
163163    .sram_read = atusb_sram_read,
164164    .interrupt_wait = atusb_interrupt_wait,
165    .rx_mode = atusb_rx_mode,
166    .rx = atusb_rx,
167    .tx = atusb_tx,
165168};

Archive Download the corresponding diff file



interactive