From 7585e5345cb325847bd79faa23347d81aeffbb52 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Fri, 31 Jul 2009 14:13:26 +0200 Subject: [PATCH] usb: getting string descriptors, minor improvements --- libs/string.cpp | 19 +++++++++++++++++++ libs/string.h | 3 +++ resources/uhci.h | 2 +- resources/usb.cpp | 25 +++++++++++++++++++++++-- resources/usb.h | 13 ++++++++++--- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/libs/string.cpp b/libs/string.cpp index f46dc88..bafa37b 100644 --- a/libs/string.cpp +++ b/libs/string.cpp @@ -20,6 +20,8 @@ * */ +#include "arch/low/general.h" + #include "string.h" #include "buffer.h" @@ -239,6 +241,23 @@ string::operator const char*() const { return data; } +const char *string::to_ascii() const { + assert("string: operations on a null string", null()); + return data; +} + +string string::from_utf16(char *_data) { + u16 *utf_data = (u16*)_data; + int size; + for (size = 0; utf_data[size]; size++); + + u8 *data = new u8[size]; + for (int i = 0; i < size; i++) + data[i] = utf_data[i]; + + return string((char*)data); +} + bool string::null() const { return length() == 0; } diff --git a/libs/string.h b/libs/string.h index f86663c..98539a6 100644 --- a/libs/string.h +++ b/libs/string.h @@ -61,6 +61,9 @@ public: } operator const char*() const; + const char *to_ascii() const; + + static string from_utf16(char*); bool null() const; diff --git a/resources/uhci.h b/resources/uhci.h index 59a1770..2fcc1bb 100644 --- a/resources/uhci.h +++ b/resources/uhci.h @@ -69,7 +69,7 @@ namespace resources { void irq(); - transfer_descriptor *td; + volatile transfer_descriptor *td; frame_pointer *fp; int last_fp; queue_head *qh; diff --git a/resources/usb.cpp b/resources/usb.cpp index 9824847..3611133 100644 --- a/resources/usb.cpp +++ b/resources/usb.cpp @@ -50,6 +50,25 @@ int usb::get_count() { #define GET_CONFIGURATION 8 #define SET_CONFIGURATION 9 +string usb::get_dev_string(int index, int addr) { + if (!index) + return string(); + + usb_setup_data setup; + setup.bmRequestType = 0x80; + setup.bRequest = GET_DESCRIPTOR; + setup.wValue = 3 << 8 | index; + setup.wIndex = 0; + setup.wLength = 1; + int size = *(char*)host->control_transfer(pid_setup, &setup, sizeof(usb_setup_data), 1, addr); + + setup.wLength = size; + char *bytes = (char*)host->control_transfer(pid_setup, &setup, sizeof(usb_setup_data), size, addr); + bytes += 2; + + return string::from_utf16(bytes); +} + void usb::device_connected(int port) { usb_count++; @@ -82,6 +101,7 @@ void usb::device_connected(int port) { setup.wLength = 16; dev = (device_descriptor*)host->control_transfer(pid_setup, &setup, sizeof(usb_setup_data), sizeof(device_descriptor),addr); + get_dev_string(dev->iProduct, addr); /* Get configuration descriptor */ setup.bmRequestType = 0x80; @@ -111,16 +131,17 @@ void usb::device_connected(int port) { } id->set_endps(control_ep, read_ep, write_ep); + id->set_conf(conf->bConfigurationValue); create_device(id); __asm__ __volatile__("cli\nhlt"::"a"(conf),"b"(write_ep),"c"(read_ep)); } -void usb::set_conf(int addr) { +void usb::set_conf(int addr, int conf) { usb_setup_data setup; setup.bmRequestType = 0; setup.bRequest = SET_CONFIGURATION; - setup.wValue = 1; + setup.wValue = conf; setup.wIndex = 0; setup.wLength = 0; diff --git a/resources/usb.h b/resources/usb.h index 866cf34..ce1eff5 100644 --- a/resources/usb.h +++ b/resources/usb.h @@ -104,6 +104,7 @@ namespace resources { } __attribute__((packed)); void device_connected(int); + string get_dev_string(int, int); public: // bool initialize(); // bool type_added(manes::type_name); @@ -111,7 +112,7 @@ namespace resources { return host; } - void set_conf(int); + void set_conf(int, int); int get_count(); @@ -132,8 +133,10 @@ namespace resources { int control_endp; int read_endp; int write_endp; + + int configuration; public: - usb_did(bus *b, int addr, p i) : did(b), address(addr), intf(i) { } + usb_did(p b, int addr, p i) : did(b), address(addr), intf(i) { } virtual void set_endps(int c, int r, int w) { control_endp = c; @@ -141,6 +144,10 @@ namespace resources { write_endp = w; } + virtual void set_conf(int c) { + configuration = c; + } + virtual int get_class() const { return intf->bInterfaceClass; } @@ -153,7 +160,7 @@ namespace resources { return intf->bInterfaceProtocol; } void accepted() { - bus_id.cast()->set_conf(address); + bus_id.cast()->set_conf(address, configuration); } virtual void bulk_read(buffer &buf) { -- 2.11.4.GIT