Root/atrf/tools/atspi-id/atspi-id.c

Source at commit c2dd23840ce5875deca09673fcb8abb8dc3a8e7a created 9 years 1 month ago.
By Werner Almesberger, Moved fw/ and tools/ into atrf/ as well.
1/*
2 * atspi-id/atspi-id.c - Identify a ben-wpan AF86RF230 board
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <usb.h>
17
18#include "at86rf230.h"
19#include "atspi/ep0.h"
20#include "atspi.h"
21
22
23#define FROM_DEV ATSPI_FROM_DEV(0)
24
25#define BUF_SIZE 256
26
27
28
29static int get_id(usb_dev_handle *dev, void *data, int size)
30{
31    int res;
32
33    res = usb_control_msg(dev, FROM_DEV, ATSPI_ID, 0, 0, data, size, 1000);
34    if (res < 0)
35        fprintf(stderr, "ATSPI_ID: %s\n", usb_strerror());
36    return res;
37}
38
39
40static int atspi_get_protocol(usb_dev_handle *dev,
41    uint8_t *major, uint8_t *minor, uint8_t *target)
42{
43    uint8_t ids[3];
44
45    if (get_id(dev, ids, 3) < 0)
46        return -1;
47    if (major)
48        *major = ids[0];
49    if (minor)
50        *minor = ids[1];
51    if (target)
52        *target = ids[2];
53
54    return 0;
55}
56 
57
58static int atspi_get_build(usb_dev_handle *dev, char *buf, size_t size)
59{
60    int res;
61
62    res = usb_control_msg(dev, FROM_DEV, ATSPI_BUILD, 0, 0, buf, size,
63        1000);
64    if (res < 0)
65        fprintf(stderr, "ATSPI_BUILD: %s\n", usb_strerror());
66    return res;
67}
68
69
70static void show_info(usb_dev_handle *dev)
71{
72    const struct usb_device *device = usb_device(dev);
73    uint8_t major, minor, target;
74    char buf[BUF_SIZE+1]; /* +1 for terminating \0 */
75    int len;
76    uint8_t part, version, man_id_0, man_id_1;
77
78    printf("%04x:%04x ",
79        device->descriptor.idVendor, device->descriptor.idProduct);
80
81    if (atspi_get_protocol(dev, &major, &minor, &target) < 0)
82        exit(1);
83    printf("protocol %u.%u hw %u\n", major, minor, target);
84
85    len = atspi_get_build(dev, buf, sizeof(buf)-1);
86    if (len < 0)
87        exit(1);
88    buf[len] = 0;
89    printf("%10s%s\n", "", buf);
90
91    part = atspi_reg_read(dev, REG_PART_NUM);
92    version = atspi_reg_read(dev, REG_VERSION_NUM);
93    man_id_0 = atspi_reg_read(dev, REG_MAN_ID_0);
94    man_id_1 = atspi_reg_read(dev, REG_MAN_ID_1);
95    printf("%10spart 0x%02x version %u manufacturer xxxx%02x%02x\n", "",
96        part, version, man_id_1, man_id_0);
97}
98
99
100static void usage(const char *name)
101{
102    fprintf(stderr, "%s\n", name);
103    exit(1);
104}
105
106
107int main(int argc, const char **argv)
108{
109    usb_dev_handle *dev;
110
111    if (argc != 1)
112        usage(*argv);
113    dev = atspi_open();
114    if (!dev)
115        return 1;
116
117    show_info(dev);
118
119    return 0;
120}
121

Archive Download this file



interactive