self.configuration_string_index = 0
self.interfaces = interfaces
+ self.attributes = 0xe0
+ self.max_power = 0x01
+
def set_configuration_string_index(self, i):
self.configuration_string_index = i
for i in self.interfaces:
interface_descriptors += i.get_descriptor()
- total_len = len(interface_descriptors) + 7
+ total_len = len(interface_descriptors) + 9
d = bytes([
- 7, # length of descriptor in bytes
+ 9, # length of descriptor in bytes
2, # descriptor type 2 == configuration
total_len & 0xff,
(total_len >> 8) & 0xff,
len(self.interfaces),
self.configuration_index,
- self.configuration_string_index
+ self.configuration_string_index,
+ self.attributes,
+ self.max_power
])
return d + interface_descriptors
elif req.get_recipient() == USB.request_recipient_interface:
recipient = self.configuration.interfaces[req.index]
elif req.get_recipient() == USB.request_recipient_endpoint:
- recipient = self.configuration.endpoints[req.index]
+ try:
+ recipient = self.endpoints[req.index]
+ except KeyError:
+ self.maxusb_app.stall_ep0()
+ return
# and then the type
if req.get_type() == USB.request_type_standard:
self.maxusb_app.stall_ep0()
def handle_data_available(self, ep_num, data):
- if self.ready and ep_num in self.endpoints:
+ if self.state == USB.state_configured and ep_num in self.endpoints:
endpoint = self.endpoints[ep_num]
endpoint.handler(data)
def handle_buffer_available(self, ep_num):
- if self.ready and ep_num in self.endpoints:
+ if self.state == USB.state_configured and ep_num in self.endpoints:
endpoint = self.endpoints[ep_num]
endpoint.handler()
else:
# string descriptors start at 1
s = self.strings[num-1].encode('utf-16')
+
+ # Linux doesn't like the leading 2-byte Byte Order Mark (BOM);
+ # FreeBSD is okay without it
+ s = s[2:]
+
d = bytearray([
len(s) + 2, # length of descriptor in bytes
3 # descriptor type 3 == string
self.descriptors[USB.desc_type_interface] = self.get_descriptor
self.request_handlers = {
- 6 : self.handle_get_descriptor_request
+ 6 : self.handle_get_descriptor_request,
+ 11 : self.handle_set_interface_request
}
# USB 2.0 specification, section 9.4.3 (p 281 of pdf)
if self.verbose > 5:
print(self.name, "sent", n, "bytes in response")
+ def handle_set_interface_request(self, req):
+ self.device.maxusb_app.stall_ep0()
+
# Table 9-12 of USB 2.0 spec (pdf page 296)
def get_descriptor(self):
def __init__(self, maxusb_app, verbose=0):
config = USBConfiguration(
1, # index
- "Maxim Emulated Keyboard Configuration", # string desc
+ "Emulated Keyboard", # string desc
[ USBKeyboardInterface() ] # interfaces
)