From 583a7b72ee2177391e6dca273a62ae17b70eb2fa Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Sun, 7 Jun 2015 00:28:03 +0200 Subject: [PATCH] atusb/fw: add EUI64 read and write fw interface to permanently set an EUI64 The kernel driver will now ask for ATUSB_EUI64_READ during init and sets this extended address if available. Use the atusb-eui64 utility from the tools folder to read or set the permanent address. After a new address is set the device will reset to make sure we are in a sane state after the change. --- atusb/fw/ep0.c | 25 +++++++++++++++++++++++++ atusb/fw/include/atusb/atusb.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c index 04a7442..d845156 100644 --- a/atusb/fw/ep0.c +++ b/atusb/fw/ep0.c @@ -3,6 +3,7 @@ * * Written 2008-2011, 2013 by Werner Almesberger * Copyright 2008-2011, 2013 Werner Almesberger + * Copyright 2015-2016 Stefan Schmidt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,6 +17,10 @@ #include #include +#include + +#define F_CPU 8000000UL +#include #ifndef NULL #define NULL 0 @@ -44,6 +49,14 @@ static uint8_t buf[MAX_PSDU+3]; /* command, PHDR, and LQI */ static uint8_t size; +static void do_eeprom_write(void *user) +{ + int i; + + for (i = 0; i < size; i++) + eeprom_update_byte((uint8_t*)i, buf[i]); +} + static void do_buf_write(void *user) { uint8_t i; @@ -246,6 +259,18 @@ static bool my_setup(const struct setup_request *setup) return mac_rx(setup->wValue); case ATUSB_TO_DEV(ATUSB_TX): return mac_tx(setup->wValue, setup->wIndex, setup->wLength); + case ATUSB_TO_DEV(ATUSB_EUI64_WRITE): + debug("ATUSB_EUI64_WRITE\n"); + usb_recv(&eps[0], buf, setup->wLength, do_eeprom_write, NULL); + _delay_ms(100); + reset_cpu(); + return 1; + + case ATUSB_FROM_DEV(ATUSB_EUI64_READ): + debug("ATUSB_EUI64_READ\n"); + eeprom_read_block(buf, (const void*)0, 8); + usb_send(&eps[0], buf, 8, NULL, NULL); + return 1; default: error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", diff --git a/atusb/fw/include/atusb/atusb.h b/atusb/fw/include/atusb/atusb.h index a4f9651..b22bbaa 100644 --- a/atusb/fw/include/atusb/atusb.h +++ b/atusb/fw/include/atusb/atusb.h @@ -46,6 +46,8 @@ enum atusb_requests { ATUSB_SPI_WRITE2_SYNC, ATUSB_RX_MODE = 0x40, /* HardMAC group */ ATUSB_TX, + ATUSB_EUI64_WRITE = 0x50, /* Parameter in EEPROM grp */ + ATUSB_EUI64_READ, }; /* @@ -77,6 +79,8 @@ enum atusb_requests { * * host-> ATUSB_RX_MODE on - 0 * host-> ATUSB_TX flags ack_seq #bytes + * host-> ATUSB_EUI64_WRITE - - #bytes (8) + * ->host ATUSB_EUI64_READ - - #bytes (8) */ #define ATUSB_REQ_FROM_DEV (USB_TYPE_VENDOR | USB_DIR_IN)