From ec97f564250a32af2861e1dfe2bd3ccd3d01ad6b Mon Sep 17 00:00:00 2001 From: emax Date: Fri, 12 Nov 2010 19:43:12 +0000 Subject: Add firmware downloader for Atheros AR3011 based USB Bluetooth devices. Hardware donated by: Rusty Nejdl rnejdl at ringofsaturn dot com Tested by: Rusty Nejdl rnejdl at ringofsaturn dot com Tested by: Andrzej Tobola ato at iem dot pw dot edu dot pl MFC after: 3 weeks --- usr.sbin/bluetooth/Makefile | 1 + usr.sbin/bluetooth/ath3kfw/Makefile | 9 ++ usr.sbin/bluetooth/ath3kfw/ath3kfw.8 | 78 ++++++++++ usr.sbin/bluetooth/ath3kfw/ath3kfw.c | 287 +++++++++++++++++++++++++++++++++++ 4 files changed, 375 insertions(+) create mode 100644 usr.sbin/bluetooth/ath3kfw/Makefile create mode 100644 usr.sbin/bluetooth/ath3kfw/ath3kfw.8 create mode 100644 usr.sbin/bluetooth/ath3kfw/ath3kfw.c (limited to 'usr.sbin') diff --git a/usr.sbin/bluetooth/Makefile b/usr.sbin/bluetooth/Makefile index ad193d0..594b440 100644 --- a/usr.sbin/bluetooth/Makefile +++ b/usr.sbin/bluetooth/Makefile @@ -2,6 +2,7 @@ # $FreeBSD$ SUBDIR= \ + ath3kfw \ bcmfw \ bt3cfw \ bthidcontrol \ diff --git a/usr.sbin/bluetooth/ath3kfw/Makefile b/usr.sbin/bluetooth/ath3kfw/Makefile new file mode 100644 index 0000000..0ff010f --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD$ + +PROG= ath3kfw +MAN= ath3kfw.8 +WARNS?= 6 +DPADD+= ${LIBUSB} +LDADD+= -lusb + +.include diff --git a/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 b/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 new file mode 100644 index 0000000..be10b47 --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/ath3kfw.8 @@ -0,0 +1,78 @@ +.\" Copyright (c) 2010 Maksim Yevmenkin +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd Novermber 9, 2010 +.Dt ATH3KFW 8 +.Os +.Sh NAME +.Nm ath3kfw +.Nd firmware download utility for Atheros AR3011 chip based Bluetooth USB devices +.Sh SYNOPSIS +.Nm +.Fl d Ar device_name +.Fl f Ar firmware_file_name +.Nm +.Fl h +.Sh DESCRIPTION +The +.Nm +utility downloads the specified firmware file to the specified +.Xr ugen 4 +device. +.Pp +This utility will +.Em only +work with Atheros AR3011 chip based Bluetooth USB devices. +The identification is currently based on USB vendor ID/product ID pair. +The vendor ID should be 0x0cf3 +.Pq Dv USB_VENDOR_ATHEROS2 +and the product ID should be 0x3000. +.Pp +Firmware files ath3k-1.fw and ath3k-2.fw can be obtained from the +linux-firmware RPM. +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl d Ar device_name +Specify +.Xr ugen 4 +device name. +.It Fl f Ar firmware_file_name +Specify firmware file name for download. +.It Fl h +Display usage message and exit. +.El +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr libusb 3 , +.Xr ugen 4 , +.Xr devd 8 +.Sh AUTHORS +.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com +.Sh BUGS +Most likely. +Please report if found. diff --git a/usr.sbin/bluetooth/ath3kfw/ath3kfw.c b/usr.sbin/bluetooth/ath3kfw/ath3kfw.c new file mode 100644 index 0000000..02d4501 --- /dev/null +++ b/usr.sbin/bluetooth/ath3kfw/ath3kfw.c @@ -0,0 +1,287 @@ +/* + * ath3kfw.c + */ + +/*- + * Copyright (c) 2010 Maksim Yevmenkin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ATH3KFW "ath3kfw" +#define ATH3KFW_VENDOR_ID 0x0cf3 +#define ATH3KFW_PRODUCT_ID 0x3000 +#define ATH3KFW_FW "/usr/local/etc/ath3k-1.fw" +#define ATH3KFW_BULK_EP 0x02 +#define ATH3KFW_REQ_DFU_DNLOAD 1 +#define ATH3KFW_MAX_BSIZE 4096 + +static int parse_ugen_name (char const *ugen, uint8_t *bus, + uint8_t *addr); +static int find_device (struct libusb20_backend *be, + uint8_t bus, uint8_t addr, + struct libusb20_device **dev); +static int download_firmware (struct libusb20_device *dev, + char const *firmware); +static void usage (void); + +/* + * Firmware downloader for Atheros AR3011 based USB Bluetooth devices + */ + +int +main(int argc, char **argv) +{ + uint8_t bus, addr; + char const *firmware; + struct libusb20_backend *be; + struct libusb20_device *dev; + int n; + + openlog(ATH3KFW, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_USER); + + bus = 0; + addr = 0; + firmware = ATH3KFW_FW; + + while ((n = getopt(argc, argv, "d:f:h")) != -1) { + switch (n) { + case 'd': /* ugen device name */ + if (parse_ugen_name(optarg, &bus, &addr) < 0) + usage(); + break; + + case 'f': /* firmware file */ + firmware = optarg; + break; + + case 'h': + default: + usage(); + break; + /* NOT REACHED */ + } + } + + be = libusb20_be_alloc_default(); + if (be == NULL) { + syslog(LOG_ERR, "libusb20_be_alloc_default() failed"); + return (-1); + } + + if (find_device(be, bus, addr, &dev) < 0) { + syslog(LOG_ERR, "ugen%d.%d is not recognized as " \ + "Atheros AR3011 based device " \ + "(possibly caused by lack of permissions)", bus, addr); + return (-1); + } + + if (download_firmware(dev, firmware) < 0) { + syslog(LOG_ERR, "could not download %s firmare to ugen%d.%d", + firmware, bus, addr); + return (-1); + } + + libusb20_be_free(be); + closelog(); + + return (0); +} + +/* + * Parse ugen name and extract device's bus and address + */ + +static int +parse_ugen_name(char const *ugen, uint8_t *bus, uint8_t *addr) +{ + char *ep; + + if (strncmp(ugen, "ugen", 4) != 0) + return (-1); + + *bus = (uint8_t) strtoul(ugen + 4, &ep, 10); + if (*ep != '.') + return (-1); + + *addr = (uint8_t) strtoul(ep + 1, &ep, 10); + if (*ep != '\0') + return (-1); + + return (0); +} + +/* + * Find USB device + */ + +static int +find_device(struct libusb20_backend *be, uint8_t bus, uint8_t addr, + struct libusb20_device **dev) +{ + struct LIBUSB20_DEVICE_DESC_DECODED *desc; + + *dev = NULL; + + while ((*dev = libusb20_be_device_foreach(be, *dev)) != NULL) { + if (libusb20_dev_get_bus_number(*dev) != bus || + libusb20_dev_get_address(*dev) != addr) + continue; + + desc = libusb20_dev_get_device_desc(*dev); + if (desc == NULL) + continue; + + if (desc->idVendor != ATH3KFW_VENDOR_ID || + desc->idProduct != ATH3KFW_PRODUCT_ID) + continue; + + break; + } + + return ((*dev == NULL)? -1 : 0); +} + +/* + * Download firmware + */ + +static int +download_firmware(struct libusb20_device *dev, char const *firmware) +{ + struct libusb20_transfer *bulk; + struct LIBUSB20_CONTROL_SETUP_DECODED req; + int fd, n, error; + uint8_t buf[ATH3KFW_MAX_BSIZE]; + + error = -1; + + if (libusb20_dev_open(dev, 1) != 0) { + syslog(LOG_ERR, "libusb20_dev_open() failed"); + return (error); + } + + if ((bulk = libusb20_tr_get_pointer(dev, 0)) == NULL) { + syslog(LOG_ERR, "libusb20_tr_get_pointer() failed"); + goto out; + } + + if (libusb20_tr_open(bulk, ATH3KFW_MAX_BSIZE, 1, ATH3KFW_BULK_EP) != 0) { + syslog(LOG_ERR, "libusb20_tr_open(%d, 1, %d) failed", + ATH3KFW_MAX_BSIZE, ATH3KFW_BULK_EP); + goto out; + } + + if ((fd = open(firmware, O_RDONLY)) < 0) { + syslog(LOG_ERR, "open(%s) failed. %s", + firmware, strerror(errno)); + goto out1; + } + + n = read(fd, buf, 20); + if (n != 20) { + syslog(LOG_ERR, "read(%s, 20) failed. %s", + firmware, strerror(errno)); + goto out2; + } + + LIBUSB20_INIT(LIBUSB20_CONTROL_SETUP, &req); + req.bmRequestType = LIBUSB20_REQUEST_TYPE_VENDOR; + req.bRequest = ATH3KFW_REQ_DFU_DNLOAD; + req.wLength = 20; + + if (libusb20_dev_request_sync(dev, &req, buf, NULL, 5000, 0) != 0) { + syslog(LOG_ERR, "libusb20_dev_request_sync() failed"); + goto out2; + } + + for (;;) { + n = read(fd, buf, sizeof(buf)); + if (n < 0) { + syslog(LOG_ERR, "read(%s, %d) failed. %s", + firmware, (int) sizeof(buf), strerror(errno)); + goto out2; + } + if (n == 0) + break; + + libusb20_tr_setup_bulk(bulk, buf, n, 3000); + libusb20_tr_start(bulk); + + while (libusb20_dev_process(dev) == 0) { + if (libusb20_tr_pending(bulk) == 0) + break; + + libusb20_dev_wait_process(dev, -1); + } + + if (libusb20_tr_get_status(bulk) != 0) { + syslog(LOG_ERR, "bulk transfer failed with status %d", + libusb20_tr_get_status(bulk)); + goto out2; + } + } + + error = 0; +out2: + close(fd); +out1: + libusb20_tr_close(bulk); +out: + libusb20_dev_close(dev); + + return (error); +} + +/* + * Display usage and exit + */ + +static void +usage(void) +{ + printf( +"Usage: %s -d ugenX.Y -f firmware_file\n" +"Usage: %s -h\n" \ +"Where:\n" \ +"\t-d ugenX.Y ugen device name\n" \ +"\t-f firmware image firmware image file name for download\n" \ +"\t-h display this message\n", ATH3KFW, ATH3KFW); + + exit(255); +} + -- cgit v1.1 From d460534b4920441a5c7fadace2f78c19c1a0d963 Mon Sep 17 00:00:00 2001 From: brucec Date: Sat, 13 Nov 2010 01:21:55 +0000 Subject: We still support PLIP devices, so mention them in addition to ethernet. --- usr.sbin/sysinstall/install.c | 2 +- usr.sbin/sysinstall/menus.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c index 4bf67ea..273f221 100644 --- a/usr.sbin/sysinstall/install.c +++ b/usr.sbin/sysinstall/install.c @@ -692,7 +692,7 @@ nodisks: "may do so by typing: /usr/sbin/sysinstall."); } if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { - if (!msgYesNo("Would you like to configure any Ethernet network devices?")) { + if (!msgYesNo("Would you like to configure any Ethernet or PLIP network devices?")) { Device *tmp = tcpDeviceSelect(); if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) diff --git a/usr.sbin/sysinstall/menus.c b/usr.sbin/sysinstall/menus.c index 2015978..271909d 100644 --- a/usr.sbin/sysinstall/menus.c +++ b/usr.sbin/sysinstall/menus.c @@ -882,7 +882,7 @@ DMenu MenuMediaFTP = { DMenu MenuNetworkDevice = { DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS, "Network interface information required", - "Please select the ethernet device to configure.\n\n" + "Please select the ethernet or PLIP device to configure.\n\n" "", "Press F1 to read network configuration manual", "network_device", -- cgit v1.1 From 6eeacebcd780af4ecce3c12d3790ac693caec7cb Mon Sep 17 00:00:00 2001 From: brucec Date: Sat, 13 Nov 2010 21:48:32 +0000 Subject: Add ftp4.se.freebsd.org to the set of mirrors. PR: bin/150552 Submitted by: Niclas Zeising MFC after: 3 days --- usr.sbin/sysinstall/menus.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'usr.sbin') diff --git a/usr.sbin/sysinstall/menus.c b/usr.sbin/sysinstall/menus.c index 271909d..e2c8f5e 100644 --- a/usr.sbin/sysinstall/menus.c +++ b/usr.sbin/sysinstall/menus.c @@ -793,6 +793,8 @@ DMenu MenuMediaFTP = { VAR_FTP_PATH "=ftp://ftp2.se.freebsd.org" }, { " Sweden #3", "ftp3.se.freebsd.org", NULL, dmenuSetVariable, NULL, VAR_FTP_PATH "=ftp://ftp3.se.freebsd.org" }, + { " Sweden #4", "ftp4.se.freebsd.org", NULL, dmenuSetVariable, NULL, + VAR_FTP_PATH "=ftp://ftp4.se.freebsd.org" }, { " Sweden #5", "ftp5.se.freebsd.org", NULL, dmenuSetVariable, NULL, VAR_FTP_PATH "=ftp://ftp5.se.freebsd.org" }, -- cgit v1.1