2008-11-25 08:04:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 AnyWi Technologies
|
|
|
|
* Author: Andrea Guzzo <aguzzo@anywi.com>
|
|
|
|
* * based on uark.c 1.1 2006/08/14 08:30:22 jsg *
|
|
|
|
* * parts from ubsa.c 183348 2008-09-25 12:00:56Z phk *
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
*
|
|
|
|
* - The detour through the tty layer is ridiculously expensive wrt
|
|
|
|
* buffering due to the high speeds.
|
|
|
|
*
|
|
|
|
* We should consider adding a simple r/w device which allows
|
|
|
|
* attaching of PPP in a more efficient way.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-02-18 06:33:10 +00:00
|
|
|
#include "usbdevs.h"
|
2009-02-23 18:31:00 +00:00
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usb_mfunc.h>
|
|
|
|
#include <dev/usb/usb_error.h>
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
#define USB_DEBUG_VAR u3g_debug
|
|
|
|
|
2009-02-23 18:31:00 +00:00
|
|
|
#include <dev/usb/usb_core.h>
|
|
|
|
#include <dev/usb/usb_debug.h>
|
|
|
|
#include <dev/usb/usb_process.h>
|
|
|
|
#include <dev/usb/usb_request.h>
|
|
|
|
#include <dev/usb/usb_lookup.h>
|
|
|
|
#include <dev/usb/usb_util.h>
|
|
|
|
#include <dev/usb/usb_busdma.h>
|
|
|
|
#include <dev/usb/usb_msctest.h>
|
|
|
|
#include <dev/usb/usb_dynamic.h>
|
|
|
|
#include <dev/usb/usb_device.h>
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-02-23 18:31:00 +00:00
|
|
|
#include <dev/usb/serial/usb_serial.h>
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
#if USB_DEBUG
|
|
|
|
static int u3g_debug = 0;
|
|
|
|
|
2009-05-21 01:48:42 +00:00
|
|
|
SYSCTL_NODE(_hw_usb, OID_AUTO, u3g, CTLFLAG_RW, 0, "USB 3g");
|
|
|
|
SYSCTL_INT(_hw_usb_u3g, OID_AUTO, debug, CTLFLAG_RW,
|
2009-02-24 05:35:48 +00:00
|
|
|
&u3g_debug, 0, "Debug level");
|
2008-11-25 08:04:40 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-07 02:17:09 +00:00
|
|
|
#define U3G_MAXPORTS 8
|
2008-11-25 08:04:40 +00:00
|
|
|
#define U3G_CONFIG_INDEX 0
|
|
|
|
#define U3G_BSIZE 2048
|
|
|
|
|
2009-01-04 00:12:01 +00:00
|
|
|
#define U3GSP_GPRS 0
|
|
|
|
#define U3GSP_EDGE 1
|
|
|
|
#define U3GSP_CDMA 2
|
|
|
|
#define U3GSP_UMTS 3
|
|
|
|
#define U3GSP_HSDPA 4
|
|
|
|
#define U3GSP_HSUPA 5
|
|
|
|
#define U3GSP_HSPA 6
|
|
|
|
#define U3GSP_MAX 7
|
|
|
|
|
2009-02-24 05:35:48 +00:00
|
|
|
#define U3GFL_HUAWEI_INIT 0x0001 /* Init command required */
|
|
|
|
#define U3GFL_SCSI_EJECT 0x0002 /* SCSI eject command required */
|
|
|
|
#define U3GFL_SIERRA_INIT 0x0004 /* Init command required */
|
|
|
|
#define U3GFL_SAEL_M460_INIT 0x0008 /* Init device */
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-01-15 02:35:40 +00:00
|
|
|
enum {
|
|
|
|
U3G_BULK_WR,
|
|
|
|
U3G_BULK_RD,
|
2009-02-09 22:05:25 +00:00
|
|
|
U3G_N_TRANSFER,
|
2009-01-15 02:35:40 +00:00
|
|
|
};
|
|
|
|
|
2008-11-25 08:04:40 +00:00
|
|
|
struct u3g_softc {
|
2009-05-28 17:36:36 +00:00
|
|
|
struct ucom_super_softc sc_super_ucom;
|
|
|
|
struct ucom_softc sc_ucom[U3G_MAXPORTS];
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER];
|
|
|
|
struct usb_device *sc_udev;
|
2009-03-02 02:44:10 +00:00
|
|
|
struct mtx sc_mtx;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
uint8_t sc_lsr; /* local status register */
|
|
|
|
uint8_t sc_msr; /* U3G status register */
|
|
|
|
uint8_t sc_numports;
|
|
|
|
};
|
|
|
|
|
|
|
|
static device_probe_t u3g_probe;
|
|
|
|
static device_attach_t u3g_attach;
|
|
|
|
static device_detach_t u3g_detach;
|
|
|
|
|
2009-05-29 18:46:57 +00:00
|
|
|
static usb_callback_t u3g_write_callback;
|
|
|
|
static usb_callback_t u3g_read_callback;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
static void u3g_start_read(struct ucom_softc *ucom);
|
|
|
|
static void u3g_stop_read(struct ucom_softc *ucom);
|
|
|
|
static void u3g_start_write(struct ucom_softc *ucom);
|
|
|
|
static void u3g_stop_write(struct ucom_softc *ucom);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-01-04 00:12:01 +00:00
|
|
|
static int u3g_driver_loaded(struct module *mod, int what, void *arg);
|
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
static const struct usb_config u3g_config[U3G_N_TRANSFER] = {
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-01-15 02:35:40 +00:00
|
|
|
[U3G_BULK_WR] = {
|
2008-11-25 08:04:40 +00:00
|
|
|
.type = UE_BULK,
|
|
|
|
.endpoint = UE_ADDR_ANY,
|
|
|
|
.direction = UE_DIR_OUT,
|
2009-04-05 18:20:38 +00:00
|
|
|
.bufsize = U3G_BSIZE,/* bytes */
|
|
|
|
.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
|
|
|
|
.callback = &u3g_write_callback,
|
2008-11-25 08:04:40 +00:00
|
|
|
},
|
|
|
|
|
2009-01-15 02:35:40 +00:00
|
|
|
[U3G_BULK_RD] = {
|
2008-11-25 08:04:40 +00:00
|
|
|
.type = UE_BULK,
|
|
|
|
.endpoint = UE_ADDR_ANY,
|
|
|
|
.direction = UE_DIR_IN,
|
2009-04-05 18:20:38 +00:00
|
|
|
.bufsize = U3G_BSIZE,/* bytes */
|
|
|
|
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
|
|
|
|
.callback = &u3g_read_callback,
|
2008-11-25 08:04:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
static const struct ucom_callback u3g_callback = {
|
2009-06-15 01:02:43 +00:00
|
|
|
.ucom_start_read = &u3g_start_read,
|
|
|
|
.ucom_stop_read = &u3g_stop_read,
|
|
|
|
.ucom_start_write = &u3g_start_write,
|
|
|
|
.ucom_stop_write = &u3g_stop_write,
|
2008-11-25 08:04:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static device_method_t u3g_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, u3g_probe),
|
|
|
|
DEVMETHOD(device_attach, u3g_attach),
|
|
|
|
DEVMETHOD(device_detach, u3g_detach),
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t u3g_devclass;
|
|
|
|
|
|
|
|
static driver_t u3g_driver = {
|
|
|
|
.name = "u3g",
|
|
|
|
.methods = u3g_methods,
|
|
|
|
.size = sizeof(struct u3g_softc),
|
|
|
|
};
|
|
|
|
|
2009-03-02 05:37:05 +00:00
|
|
|
DRIVER_MODULE(u3g, uhub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0);
|
2009-02-23 18:31:00 +00:00
|
|
|
MODULE_DEPEND(u3g, ucom, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(u3g, usb, 1, 1, 1);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
static const struct usb_device_id u3g_devs[] = {
|
2009-05-07 02:13:56 +00:00
|
|
|
#define U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Option */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(OPTION, GT3G, 0),
|
|
|
|
U3G_DEV(OPTION, GT3GQUAD, 0),
|
|
|
|
U3G_DEV(OPTION, GT3GPLUS, 0),
|
|
|
|
U3G_DEV(OPTION, GTMAX36, 0),
|
2009-05-21 17:47:27 +00:00
|
|
|
U3G_DEV(OPTION, GTHSDPA, 0),
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(OPTION, GTMAXHSUPA, 0),
|
|
|
|
U3G_DEV(OPTION, VODAFONEMC3G, 0),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Qualcomm, Inc. */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GFL_SCSI_EJECT),
|
|
|
|
U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GFL_SCSI_EJECT),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Huawei */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(HUAWEI, MOBILE, U3GFL_HUAWEI_INIT),
|
|
|
|
U3G_DEV(HUAWEI, E220, U3GFL_HUAWEI_INIT),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Novatel */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(NOVATEL, CDMA_MODEM, 0),
|
|
|
|
U3G_DEV(NOVATEL, ES620, 0),
|
|
|
|
U3G_DEV(NOVATEL, MC950D, 0),
|
|
|
|
U3G_DEV(NOVATEL, U720, 0),
|
|
|
|
U3G_DEV(NOVATEL, U727, 0),
|
|
|
|
U3G_DEV(NOVATEL, U740, 0),
|
|
|
|
U3G_DEV(NOVATEL, U740_2, 0),
|
|
|
|
U3G_DEV(NOVATEL, U870, 0),
|
|
|
|
U3G_DEV(NOVATEL, V620, 0),
|
|
|
|
U3G_DEV(NOVATEL, V640, 0),
|
|
|
|
U3G_DEV(NOVATEL, V720, 0),
|
|
|
|
U3G_DEV(NOVATEL, V740, 0),
|
|
|
|
U3G_DEV(NOVATEL, X950D, 0),
|
|
|
|
U3G_DEV(NOVATEL, XU870, 0),
|
|
|
|
U3G_DEV(NOVATEL, ZEROCD, U3GFL_SCSI_EJECT),
|
|
|
|
U3G_DEV(DELL, U740, 0),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Merlin */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(MERLIN, V620, 0),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* OEM: Sierra Wireless: */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(SIERRA, AIRCARD580, 0),
|
|
|
|
U3G_DEV(SIERRA, AIRCARD595, 0),
|
|
|
|
U3G_DEV(SIERRA, AC595U, 0),
|
|
|
|
U3G_DEV(SIERRA, AC597E, 0),
|
|
|
|
U3G_DEV(SIERRA, C597, 0),
|
|
|
|
U3G_DEV(SIERRA, AC880, 0),
|
|
|
|
U3G_DEV(SIERRA, AC880E, 0),
|
|
|
|
U3G_DEV(SIERRA, AC880U, 0),
|
|
|
|
U3G_DEV(SIERRA, AC881, 0),
|
|
|
|
U3G_DEV(SIERRA, AC881E, 0),
|
|
|
|
U3G_DEV(SIERRA, AC881U, 0),
|
2009-05-07 02:17:09 +00:00
|
|
|
U3G_DEV(SIERRA, AC885U, 0),
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(SIERRA, EM5625, 0),
|
|
|
|
U3G_DEV(SIERRA, MC5720, 0),
|
|
|
|
U3G_DEV(SIERRA, MC5720_2, 0),
|
|
|
|
U3G_DEV(SIERRA, MC5725, 0),
|
|
|
|
U3G_DEV(SIERRA, MINI5725, 0),
|
|
|
|
U3G_DEV(SIERRA, AIRCARD875, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8755, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8755_2, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8755_3, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8765, 0),
|
|
|
|
U3G_DEV(SIERRA, AC875U, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8775_2, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8780, 0),
|
|
|
|
U3G_DEV(SIERRA, MC8781, 0),
|
|
|
|
U3G_DEV(HP, HS2300, 0),
|
2009-01-04 00:12:01 +00:00
|
|
|
/* Sierra TruInstaller device ID */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(SIERRA, TRUINSTALL, U3GFL_SIERRA_INIT),
|
2009-02-24 05:35:48 +00:00
|
|
|
/* PRUEBA SILABS */
|
2009-05-07 02:13:56 +00:00
|
|
|
U3G_DEV(SILABS, SAEL, U3GFL_SAEL_M460_INIT),
|
2009-01-04 00:12:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_sierra_init(struct usb_device *udev)
|
2009-01-04 00:12:01 +00:00
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_device_request req;
|
2009-01-04 00:12:01 +00:00
|
|
|
|
|
|
|
DPRINTFN(0, "\n");
|
|
|
|
|
|
|
|
req.bmRequestType = UT_VENDOR;
|
|
|
|
req.bRequest = UR_SET_INTERFACE;
|
|
|
|
USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
|
|
|
|
USETW(req.wIndex, UHF_PORT_CONNECTION);
|
|
|
|
USETW(req.wLength, 0);
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
if (usbd_do_request_flags(udev, NULL, &req,
|
2009-01-04 00:12:01 +00:00
|
|
|
NULL, 0, NULL, USB_MS_HZ)) {
|
|
|
|
/* ignore any errors */
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_huawei_init(struct usb_device *udev)
|
2009-01-04 00:12:01 +00:00
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_device_request req;
|
2009-01-04 00:12:01 +00:00
|
|
|
|
|
|
|
DPRINTFN(0, "\n");
|
|
|
|
|
|
|
|
req.bmRequestType = UT_WRITE_DEVICE;
|
|
|
|
req.bRequest = UR_SET_FEATURE;
|
|
|
|
USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
|
|
|
|
USETW(req.wIndex, UHF_PORT_SUSPEND);
|
|
|
|
USETW(req.wLength, 0);
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
if (usbd_do_request_flags(udev, NULL, &req,
|
2009-01-04 00:12:01 +00:00
|
|
|
NULL, 0, NULL, USB_MS_HZ)) {
|
|
|
|
/* ignore any errors */
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-24 05:35:48 +00:00
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_sael_m460_init(struct usb_device *udev)
|
2009-02-24 05:35:48 +00:00
|
|
|
{
|
|
|
|
static const uint8_t setup[][24] = {
|
|
|
|
{ 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
|
|
|
0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 },
|
|
|
|
{ 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },
|
|
|
|
{ 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
|
|
|
{ 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
|
|
|
|
{ 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
|
|
|
0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
|
|
|
0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
|
|
|
|
{ 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
|
|
|
0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
|
|
|
0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
|
|
|
|
{ 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_device_request req;
|
2009-05-29 18:46:57 +00:00
|
|
|
usb_error_t err;
|
2009-02-24 05:35:48 +00:00
|
|
|
uint16_t len;
|
|
|
|
uint8_t buf[0x300];
|
|
|
|
uint8_t n;
|
|
|
|
|
|
|
|
DPRINTFN(1, "\n");
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
if (usbd_req_set_alt_interface_no(udev, NULL, 0, 0)) {
|
2009-02-24 05:35:48 +00:00
|
|
|
DPRINTFN(0, "Alt setting 0 failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) {
|
|
|
|
|
|
|
|
memcpy(&req, setup[n], sizeof(req));
|
|
|
|
|
|
|
|
len = UGETW(req.wLength);
|
|
|
|
if (req.bmRequestType & UE_DIR_IN) {
|
|
|
|
if (len > sizeof(buf)) {
|
|
|
|
DPRINTFN(0, "too small buffer\n");
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-15 01:02:43 +00:00
|
|
|
err = usbd_do_request(udev, NULL, &req, buf);
|
2009-02-24 05:35:48 +00:00
|
|
|
} else {
|
|
|
|
if (len > (sizeof(setup[0]) - 8)) {
|
|
|
|
DPRINTFN(0, "too small buffer\n");
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-15 01:02:43 +00:00
|
|
|
err = usbd_do_request(udev, NULL, &req,
|
2009-03-08 22:55:17 +00:00
|
|
|
__DECONST(uint8_t *, &setup[n][8]));
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
DPRINTFN(1, "request %u failed\n",
|
|
|
|
(unsigned int)n);
|
|
|
|
/*
|
|
|
|
* Some of the requests will fail. Stop doing
|
|
|
|
* requests when we are getting timeouts so
|
|
|
|
* that we don't block the explore/attach
|
|
|
|
* thread forever.
|
|
|
|
*/
|
|
|
|
if (err == USB_ERR_TIMEOUT)
|
2009-02-24 05:35:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-04 00:12:01 +00:00
|
|
|
static int
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_lookup_huawei(struct usb_attach_arg *uaa)
|
2009-01-04 00:12:01 +00:00
|
|
|
{
|
|
|
|
/* Calling the lookup function will also set the driver info! */
|
2009-06-15 01:02:43 +00:00
|
|
|
return (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa));
|
2009-01-04 00:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following function handles 3G modem devices (E220, Mobile,
|
|
|
|
* etc.) with auto-install flash disks for Windows/MacOSX on the first
|
|
|
|
* interface. After some command or some delay they change appearance
|
|
|
|
* to a modem.
|
|
|
|
*/
|
2009-05-29 18:46:57 +00:00
|
|
|
static usb_error_t
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_test_huawei_autoinst(struct usb_device *udev,
|
|
|
|
struct usb_attach_arg *uaa)
|
2009-01-04 00:12:01 +00:00
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_interface *iface;
|
|
|
|
struct usb_interface_descriptor *id;
|
2009-01-04 00:12:01 +00:00
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
if (udev == NULL) {
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
2009-06-15 01:02:43 +00:00
|
|
|
iface = usbd_get_iface(udev, 0);
|
2009-01-04 00:12:01 +00:00
|
|
|
if (iface == NULL) {
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
|
|
|
id = iface->idesc;
|
|
|
|
if (id == NULL) {
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
|
|
|
if (id->bInterfaceClass != UICLASS_MASS) {
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
|
|
|
if (u3g_lookup_huawei(uaa)) {
|
|
|
|
/* no device match */
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
|
|
|
flags = USB_GET_DRIVER_INFO(uaa);
|
|
|
|
|
|
|
|
if (flags & U3GFL_HUAWEI_INIT) {
|
|
|
|
u3g_huawei_init(udev);
|
|
|
|
} else if (flags & U3GFL_SCSI_EJECT) {
|
2009-06-15 01:02:43 +00:00
|
|
|
return (usb_test_autoinstall(udev, 0, 1));
|
2009-01-04 00:12:01 +00:00
|
|
|
} else if (flags & U3GFL_SIERRA_INIT) {
|
|
|
|
u3g_sierra_init(udev);
|
|
|
|
} else {
|
|
|
|
/* no quirks */
|
|
|
|
return (USB_ERR_INVAL);
|
|
|
|
}
|
|
|
|
return (0); /* success */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
u3g_driver_loaded(struct module *mod, int what, void *arg)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
/* register our autoinstall handler */
|
2009-06-15 01:02:43 +00:00
|
|
|
usb_test_huawei_autoinst_p = &u3g_test_huawei_autoinst;
|
2009-01-04 00:12:01 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2009-06-15 01:02:43 +00:00
|
|
|
usb_test_huawei_unload(NULL);
|
2009-01-04 00:12:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-11-25 08:04:40 +00:00
|
|
|
static int
|
|
|
|
u3g_probe(device_t self)
|
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_attach_arg *uaa = device_get_ivars(self);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-05-21 00:04:17 +00:00
|
|
|
if (uaa->usb_mode != USB_MODE_HOST) {
|
2008-11-25 08:04:40 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (uaa->info.bInterfaceClass != UICLASS_VENDOR) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2009-01-04 00:12:01 +00:00
|
|
|
return (u3g_lookup_huawei(uaa));
|
2008-11-25 08:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
u3g_attach(device_t dev)
|
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_config u3g_config_tmp[U3G_N_TRANSFER];
|
|
|
|
struct usb_attach_arg *uaa = device_get_ivars(dev);
|
2008-11-25 08:04:40 +00:00
|
|
|
struct u3g_softc *sc = device_get_softc(dev);
|
2009-05-28 17:36:36 +00:00
|
|
|
struct usb_interface *iface;
|
|
|
|
struct usb_interface_descriptor *id;
|
2009-05-07 17:05:03 +00:00
|
|
|
uint32_t iface_valid;
|
|
|
|
int error, flags, nports;
|
2009-05-07 02:15:58 +00:00
|
|
|
int ep, n;
|
2009-02-09 22:05:25 +00:00
|
|
|
uint8_t i;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
DPRINTF("sc=%p\n", sc);
|
|
|
|
|
2009-02-24 05:35:48 +00:00
|
|
|
flags = USB_GET_DRIVER_INFO(uaa);
|
|
|
|
|
|
|
|
if (flags & U3GFL_SAEL_M460_INIT)
|
|
|
|
u3g_sael_m460_init(uaa->device);
|
|
|
|
|
2009-01-26 17:47:32 +00:00
|
|
|
/* copy in USB config */
|
|
|
|
for (n = 0; n != U3G_N_TRANSFER; n++)
|
|
|
|
u3g_config_tmp[n] = u3g_config[n];
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
device_set_usb_desc(dev);
|
2009-03-02 02:44:10 +00:00
|
|
|
mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
sc->sc_udev = uaa->device;
|
|
|
|
|
2009-05-07 02:15:58 +00:00
|
|
|
/* Claim all interfaces on the device */
|
|
|
|
iface_valid = 0;
|
|
|
|
for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) {
|
2009-06-15 01:02:43 +00:00
|
|
|
iface = usbd_get_iface(uaa->device, i);
|
2009-05-07 02:15:58 +00:00
|
|
|
if (iface == NULL)
|
|
|
|
break;
|
2009-06-15 01:02:43 +00:00
|
|
|
id = usbd_get_interface_descriptor(iface);
|
2009-05-07 02:15:58 +00:00
|
|
|
if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR)
|
|
|
|
continue;
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex);
|
2009-05-07 02:15:58 +00:00
|
|
|
iface_valid |= (1<<i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0; /* interface index */
|
|
|
|
ep = 0; /* endpoint index */
|
|
|
|
nports = 0; /* number of ports */
|
|
|
|
while (i < USB_IFACE_MAX) {
|
|
|
|
if ((iface_valid & (1<<i)) == 0) {
|
|
|
|
i++;
|
2009-02-09 22:05:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-01-26 17:47:32 +00:00
|
|
|
|
2009-05-07 02:15:58 +00:00
|
|
|
/* update BULK endpoint index */
|
|
|
|
for (n = 0; n < U3G_N_TRANSFER; n++)
|
|
|
|
u3g_config_tmp[n].ep_index = ep;
|
|
|
|
|
2009-01-26 17:47:32 +00:00
|
|
|
/* try to allocate a set of BULK endpoints */
|
2009-06-15 01:02:43 +00:00
|
|
|
error = usbd_transfer_setup(uaa->device, &i,
|
2009-05-07 02:15:58 +00:00
|
|
|
sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER,
|
|
|
|
&sc->sc_ucom[nports], &sc->sc_mtx);
|
2009-01-26 17:47:32 +00:00
|
|
|
if (error) {
|
2009-02-09 22:05:25 +00:00
|
|
|
/* next interface */
|
2009-05-07 02:15:58 +00:00
|
|
|
i++;
|
|
|
|
ep = 0;
|
2009-02-09 22:05:25 +00:00
|
|
|
continue;
|
2009-01-26 17:47:32 +00:00
|
|
|
}
|
2009-02-09 22:05:25 +00:00
|
|
|
|
2009-01-26 17:47:32 +00:00
|
|
|
/* set stall by default */
|
2009-03-02 02:44:10 +00:00
|
|
|
mtx_lock(&sc->sc_mtx);
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]);
|
|
|
|
usbd_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]);
|
2009-03-02 02:44:10 +00:00
|
|
|
mtx_unlock(&sc->sc_mtx);
|
2009-02-09 22:05:25 +00:00
|
|
|
|
2009-05-07 02:15:58 +00:00
|
|
|
nports++; /* found one port */
|
|
|
|
ep++;
|
|
|
|
if (nports == U3G_MAXPORTS)
|
|
|
|
break;
|
2008-11-25 08:04:40 +00:00
|
|
|
}
|
2009-05-07 02:15:58 +00:00
|
|
|
if (nports == 0) {
|
|
|
|
device_printf(dev, "no ports found\n");
|
|
|
|
goto detach;
|
|
|
|
}
|
|
|
|
sc->sc_numports = nports;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom,
|
2009-03-02 02:44:10 +00:00
|
|
|
sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx);
|
2008-11-25 08:04:40 +00:00
|
|
|
if (error) {
|
2009-06-15 01:02:43 +00:00
|
|
|
DPRINTF("ucom_attach failed\n");
|
2008-11-25 08:04:40 +00:00
|
|
|
goto detach;
|
|
|
|
}
|
2009-05-07 02:15:58 +00:00
|
|
|
if (sc->sc_numports > 1)
|
|
|
|
device_printf(dev, "Found %u ports.\n", sc->sc_numports);
|
2008-11-25 08:04:40 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
detach:
|
|
|
|
u3g_detach(dev);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
u3g_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct u3g_softc *sc = device_get_softc(dev);
|
2009-01-26 17:47:32 +00:00
|
|
|
uint8_t m;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
DPRINTF("sc=%p\n", sc);
|
|
|
|
|
2009-01-26 17:47:32 +00:00
|
|
|
/* NOTE: It is not dangerous to detach more ports than attached! */
|
2009-06-15 01:02:43 +00:00
|
|
|
ucom_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
2009-01-26 17:47:32 +00:00
|
|
|
for (m = 0; m != U3G_MAXPORTS; m++)
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER);
|
2009-03-02 02:44:10 +00:00
|
|
|
mtx_destroy(&sc->sc_mtx);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_start_read(struct ucom_softc *ucom)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
|
|
|
struct u3g_softc *sc = ucom->sc_parent;
|
|
|
|
|
|
|
|
/* start read endpoint */
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]);
|
2008-11-25 08:04:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_stop_read(struct ucom_softc *ucom)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
|
|
|
struct u3g_softc *sc = ucom->sc_parent;
|
|
|
|
|
|
|
|
/* stop read endpoint */
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]);
|
2008-11-25 08:04:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_start_write(struct ucom_softc *ucom)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
|
|
|
struct u3g_softc *sc = ucom->sc_parent;
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]);
|
2008-11-25 08:04:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_stop_write(struct ucom_softc *ucom)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
|
|
|
struct u3g_softc *sc = ucom->sc_parent;
|
|
|
|
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]);
|
2008-11-25 08:04:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_write_callback(struct usb_xfer *xfer)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct ucom_softc *ucom = xfer->priv_sc;
|
2008-11-25 08:04:40 +00:00
|
|
|
uint32_t actlen;
|
|
|
|
|
|
|
|
switch (USB_GET_STATE(xfer)) {
|
|
|
|
case USB_ST_TRANSFERRED:
|
|
|
|
case USB_ST_SETUP:
|
|
|
|
tr_setup:
|
2009-06-15 01:02:43 +00:00
|
|
|
if (ucom_get_data(ucom, xfer->frbuffers, 0,
|
2008-11-25 08:04:40 +00:00
|
|
|
U3G_BSIZE, &actlen)) {
|
|
|
|
xfer->frlengths[0] = actlen;
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_submit(xfer);
|
2008-11-25 08:04:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Error */
|
|
|
|
if (xfer->error != USB_ERR_CANCELLED) {
|
|
|
|
/* do a builtin clear-stall */
|
|
|
|
xfer->flags.stall_pipe = 1;
|
|
|
|
goto tr_setup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-28 17:36:36 +00:00
|
|
|
u3g_read_callback(struct usb_xfer *xfer)
|
2008-11-25 08:04:40 +00:00
|
|
|
{
|
2009-05-28 17:36:36 +00:00
|
|
|
struct ucom_softc *ucom = xfer->priv_sc;
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
switch (USB_GET_STATE(xfer)) {
|
|
|
|
case USB_ST_TRANSFERRED:
|
2009-06-15 01:02:43 +00:00
|
|
|
ucom_put_data(ucom, xfer->frbuffers, 0, xfer->actlen);
|
2008-11-25 08:04:40 +00:00
|
|
|
|
|
|
|
case USB_ST_SETUP:
|
|
|
|
tr_setup:
|
|
|
|
xfer->frlengths[0] = xfer->max_data_length;
|
2009-06-15 01:02:43 +00:00
|
|
|
usbd_transfer_submit(xfer);
|
2008-11-25 08:04:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* Error */
|
|
|
|
if (xfer->error != USB_ERR_CANCELLED) {
|
|
|
|
/* do a builtin clear-stall */
|
|
|
|
xfer->flags.stall_pipe = 1;
|
|
|
|
goto tr_setup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|