Root/atusb/fw/sernum.c

Source at commit 85f60de9d52195afb3a0232a03e850d96584bb9a created 8 years 2 months ago.
By Werner Almesberger, atusb/fw: use the unique serial number of the ATmega8/16/32U2 for iSerialNumber
1/*
2 * fw/sernum.c - ATUSB serial number
3 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 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 <stdint.h>
15
16#include "usb.h"
17
18#include "board.h"
19#include "sernum.h"
20
21
22static const uint8_t string_descriptor_0[] = {
23    4, /* blength */
24    USB_DT_STRING, /* bDescriptorType */
25    LE(USB_LANGID_ENGLISH_US) /* wLANGID[0] */
26};
27
28
29int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
30    uint8_t *size)
31{
32    if (type != USB_DT_STRING)
33        return 0;
34    switch (index) {
35    case 0:
36        *reply = string_descriptor_0;
37        *size = sizeof(string_descriptor_0);
38        return 1;
39    case 1:
40        *reply = board_sernum;
41        *size = sizeof(board_sernum);
42        return 1;
43    default:
44        return 0;
45    }
46}
47

Archive Download this file



interactive