2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
#include <grub/serial.h>
20
#include <grub/usbserial.h>
23
grub_usbserial_fini (struct grub_serial_port *port)
25
port->usbdev->config[port->configno].interf[port->interfno].detach_hook = 0;
26
port->usbdev->config[port->configno].interf[port->interfno].attached = 0;
30
grub_usbserial_detach (grub_usb_device_t usbdev, int configno, int interfno)
32
static struct grub_serial_port *port;
33
port = usbdev->config[configno].interf[interfno].detach_data;
35
grub_serial_unregister (port);
38
static int usbnum = 0;
41
grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
42
struct grub_serial_driver *driver)
44
struct grub_serial_port *port;
46
struct grub_usb_desc_if *interf;
47
grub_usb_err_t err = GRUB_USB_ERR_NONE;
49
interf = usbdev->config[configno].interf[interfno].descif;
51
port = grub_malloc (sizeof (*port));
58
port->name = grub_xasprintf ("usb%d", usbnum++);
66
port->usbdev = usbdev;
67
port->driver = driver;
68
for (j = 0; j < interf->endpointcnt; j++)
70
struct grub_usb_desc_endp *endp;
71
endp = &usbdev->config[0].interf[interfno].descendp[j];
73
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
75
/* Bulk IN endpoint. */
78
else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
80
/* Bulk OUT endpoint. */
81
port->out_endp = endp;
85
/* Configure device */
86
if (port->out_endp && port->in_endp)
87
err = grub_usb_set_configuration (usbdev, configno + 1);
89
if (!port->out_endp || !port->in_endp || err)
91
grub_free (port->name);
96
port->configno = configno;
97
port->interfno = interfno;
99
grub_serial_config_defaults (port);
100
grub_serial_register (port);
102
port->usbdev->config[port->configno].interf[port->interfno].detach_hook
103
= grub_usbserial_detach;
104
port->usbdev->config[port->configno].interf[port->interfno].detach_data
111
grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size)
116
if (port->bufstart < port->bufend)
117
return port->buf[port->bufstart++];
119
err = grub_usb_bulk_read_extended (port->usbdev, port->in_endp->endp_addr,
120
sizeof (port->buf), port->buf, 10,
122
if (err != GRUB_USB_ERR_NONE)
125
port->bufstart = header_size;
126
port->bufend = actual;
127
if (port->bufstart >= port->bufend)
130
return port->buf[port->bufstart++];