- init() method added to the USB device class

- new USB device class method get_info() for improved device connect BX_INFOs
- USB printer: output file creation failure now causes BX_ERROR and disconnect
  instead of BX_PANIC (similar to usb_msd)
- removed obsolete include statements
This commit is contained in:
Volker Ruppert 2010-12-05 13:09:41 +00:00
parent dab658f136
commit cd7b703a5b
8 changed files with 65 additions and 44 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_common.h,v 1.11 2009-12-04 13:01:41 sshwarts Exp $
// $Id: usb_common.h,v 1.12 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -133,6 +133,9 @@ public:
usb_device_c(void);
virtual ~usb_device_c() {}
virtual bx_bool init() {return 1;}
virtual const char* get_info() {return NULL;}
virtual int handle_packet(USBPacket *p);
virtual void handle_reset() {}
virtual int handle_control(int request, int value, int index, int length, Bit8u *data) {return 0;}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_hub.cc,v 1.12 2009-04-12 07:26:58 vruppert Exp $
// $Id: usb_hub.cc,v 1.13 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -33,7 +33,6 @@
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
#include "usb_common.h"
#include "usb_hub.h"
#include "usb_msd.h"
#define LOG_THIS
@ -596,13 +595,12 @@ void usb_hub_device_c::usb_set_connect_status(Bit8u port, int type, bx_bool conn
hub.usb_port[port].PortStatus |= PORT_STAT_LOW_SPEED;
else
hub.usb_port[port].PortStatus &= ~PORT_STAT_LOW_SPEED;
if (((type == USB_DEV_TYPE_DISK) || (type == USB_DEV_TYPE_CDROM)) &&
(!device->get_connected())) {
if (!((usb_msd_device_c*)device)->init()) {
if (!device->get_connected()) {
if (!device->init()) {
usb_set_connect_status(port, type, 0);
BX_ERROR(("port #%d: connect failed", port+1));
} else {
BX_INFO(("%s on USB port #%d: '%s'", (type == USB_DEV_TYPE_DISK) ? "HD":"CD",
port+1, ((usb_msd_device_c*)device)->get_path()));
BX_INFO(("port #%d: connect: %s", port+1, device->get_info()));
}
}
} else {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_msd.cc,v 1.24 2009-04-21 15:37:17 vruppert Exp $
// $Id: usb_msd.cc,v 1.25 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -213,9 +213,15 @@ bx_bool usb_msd_device_c::init()
s.scsi_dev->register_state(s.sr_list, "scsidev");
s.mode = USB_MSDM_CBW;
d.connected = 1;
sprintf(s.info_txt, "USB %s: path='%s'", d.type==USB_DEV_TYPE_DISK ? "HD" : "CD", s.fname);
return 1;
}
const char* usb_msd_device_c::get_info()
{
return s.info_txt;
}
void usb_msd_device_c::register_state_specific(bx_list_c *parent)
{
s.sr_list = new bx_list_c(parent, "s", "USB MSD Device State", 8);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_msd.h,v 1.13 2009-04-06 15:36:55 vruppert Exp $
// $Id: usb_msd.h,v 1.14 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -33,8 +33,9 @@ public:
usb_msd_device_c(usbdev_type type, const char *filename);
virtual ~usb_msd_device_c(void);
bx_bool init();
const char* get_path() {return s.fname;}
virtual bx_bool init();
virtual const char* get_info();
virtual void handle_reset();
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
virtual int handle_data(USBPacket *p);
@ -67,6 +68,7 @@ private:
bx_list_c *sr_list;
const char *fname;
bx_list_c *config;
char info_txt[BX_PATHNAME_LEN];
} s;
static const char *cd_param_string_handler(bx_param_string_c *param, int set,

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_ohci.cc,v 1.36 2010-11-23 14:59:36 sshwarts Exp $
// $Id: usb_ohci.cc,v 1.37 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -35,9 +35,6 @@
#include "pci.h"
#include "usb_common.h"
#include "usb_hid.h"
#include "usb_hub.h"
#include "usb_msd.h"
#include "usb_ohci.h"
#define LOG_THIS theUSB_OHCI->
@ -1432,13 +1429,12 @@ void bx_usb_ohci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect
BX_OHCI_THIS hub.usb_port[port].HcRhPortStatus.lsda =
(device->get_speed() == USB_SPEED_LOW);
BX_OHCI_THIS hub.usb_port[port].HcRhPortStatus.ccs = 1;
if (((type == USB_DEV_TYPE_DISK) || (type == USB_DEV_TYPE_CDROM)) &&
(!device->get_connected())) {
if (!((usb_msd_device_c*)device)->init()) {
if (!device->get_connected()) {
if (!device->init()) {
usb_set_connect_status(port, type, 0);
BX_ERROR(("port #%d: connect failed", port+1));
} else {
BX_INFO(("%s on USB port #%d: '%s'", (type == USB_DEV_TYPE_DISK) ? "HD":"CD",
port+1, ((usb_msd_device_c*)device)->get_path()));
BX_INFO(("port #%d: connect: %s", port+1, device->get_info()));
}
}
} else { // not connected

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_printer.cc,v 1.3 2010-01-02 16:54:40 vruppert Exp $
// $Id: usb_printer.cc,v 1.4 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin David Lunt
@ -114,21 +114,37 @@ usb_printer_device_c::usb_printer_device_c(usbdev_type type, const char *filenam
{
d.type = type;
d.speed = USB_SPEED_FULL;
strcpy(d.devname, "USB Printer");
d.connected = 1;
memset((void*)&s, 0, sizeof(s));
strncpy(s.fname, filename, 255);
s.fp = fopen(s.fname, "w+b");
if (s.fp == NULL)
BX_PANIC(("Could not create/open %s", s.fname));
strcpy(d.devname, "USB Printer");
s.fname = filename;
s.fp = NULL;
put("USBPR");
}
usb_printer_device_c::~usb_printer_device_c(void)
{
fclose(s.fp);
if (s.fp != NULL) {
fclose(s.fp);
}
}
bx_bool usb_printer_device_c::init()
{
s.fp = fopen(s.fname, "w+b");
if (s.fp == NULL) {
BX_ERROR(("Could not create/open %s", s.fname));
return 0;
} else {
sprintf(s.info_txt, "USB printer: file=%s", s.fname);
d.connected = 1;
return 1;
}
}
const char* usb_printer_device_c::get_info()
{
return s.info_txt;
}
void usb_printer_device_c::register_state_specific(bx_list_c *parent)
@ -237,7 +253,7 @@ int usb_printer_device_c::handle_control(int request, int value, int index, int
case EndpointOutRequest | USB_REQ_SET_INTERFACE:
ret = 0;
break;
/* printer specific requests */
case InterfaceInClassRequest | 0x00: // 1284 get device id string
memcpy(data, bx_device_id_string, sizeof(bx_device_id_string));
@ -267,7 +283,7 @@ int usb_printer_device_c::handle_control(int request, int value, int index, int
int usb_printer_device_c::handle_data(USBPacket *p)
{
int ret = 0;
switch(p->pid) {
case USB_TOKEN_IN:
if (p->devep == 1) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_printer.h,v 1.2 2009-12-04 17:54:22 sshwarts Exp $
// $Id: usb_printer.h,v 1.3 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin David Lunt
@ -27,6 +27,9 @@ public:
usb_printer_device_c(usbdev_type type, const char *filename);
virtual ~usb_printer_device_c(void);
virtual bx_bool init();
virtual const char* get_info();
virtual void handle_reset();
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
virtual int handle_data(USBPacket *p);
@ -35,8 +38,9 @@ public:
private:
struct {
Bit8u printer_status;
char fname[BX_PATHNAME_LEN];
const char *fname;
FILE *fp;
char info_txt[BX_PATHNAME_LEN];
} s;
};

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_uhci.cc,v 1.28 2009-07-19 17:49:27 vruppert Exp $
// $Id: usb_uhci.cc,v 1.29 2010-12-05 13:09:41 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -34,9 +34,6 @@
#include "pci.h"
#include "usb_common.h"
#include "usb_hid.h"
#include "usb_hub.h"
#include "usb_msd.h"
#include "usb_uhci.h"
#define LOG_THIS theUSB_UHCI->
@ -1048,13 +1045,12 @@ void bx_usb_uhci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect
}
}
if (((type == USB_DEV_TYPE_DISK) || (type == USB_DEV_TYPE_CDROM)) &&
(!device->get_connected())) {
if (!((usb_msd_device_c*)device)->init()) {
if (!device->get_connected()) {
if (!device->init()) {
usb_set_connect_status(port, type, 0);
BX_ERROR(("port #%d: connect failed", port+1));
} else {
BX_INFO(("%s on USB port #%d: '%s'", (type == USB_DEV_TYPE_DISK) ? "HD":"CD",
port+1, ((usb_msd_device_c*)device)->get_path()));
BX_INFO(("port #%d: connect: %s", port+1, device->get_info()));
}
}
} else {