Offset a pointer in x86 Assembly - pointers

Code first, problem after.
This code has a block of data I am calling file, the block of data is as such:
filename
file_pointer
openas
Then, in generateFile we have -20(%ebp) which is a pointer to the first element in the data block, or -8(%ebp).
We call this function inside of main and offset the pointer to be able to print out filename and openas.
.section .data
strLOCK0:
.asciz "r"
strLOCK1:
.asciz "hello.txt"
strLOCK2:
.asciz "%s\n"
strLOCK3:
.asciz "%d\n"
.section .text
.globl _start
_start:
call main
movl %eax, %ebx
movl $1, %eax
int $0x80
.type generateFile, #function
generateFile:
pushl %ebp
movl %esp, %ebp
subl $20, %esp
movl 12(%ebp), %ecx
pushl %ecx
movl 8(%ebp), %ecx
pushl %ecx
call fopen
movl %eax, %ecx
movl %ecx, -4(%ebp)
movl 8(%ebp), %ecx
movl %ecx, -8(%ebp)
movl -4(%ebp), %ecx
movl %ecx, -12(%ebp)
movl 12(%ebp), %ecx
movl %ecx, -16(%ebp)
leal -8(%ebp), %ecx
movl %ecx, -20(%ebp)
movl -20(%ebp), %ecx
movl %ecx, %eax
leave
ret
.type main, #function
main:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl $strLOCK0, %ecx
pushl %ecx
movl $strLOCK1, %ecx
pushl %ecx
call generateFile
movl %eax, %ecx
movl %ecx, -4(%ebp)
movl -4(%ebp), %ebx
movl (%ebx), %ecx
pushl %ecx
movl $strLOCK2, %ecx
pushl %ecx
call printf
popl %ebx
movl -4(%ebp), %ebx
movl -8(%ebx), %ecx
pushl %ecx
movl $strLOCK3, %ecx
pushl %ecx
call printf
popl %ebx
movl $0, %ecx
movl %ecx, %eax
leave
ret
The problem is instead of the expected output of:
hello.txt
r
Instead I get:
hello.txt
-852052
I have tried different things such as
4(%ebx)
When I am getting a value, but it doesn't work.
How can I fix this?

Related

ESP8266 constantly resetting, but blink script works

Hello I have been using the Wemos D1 mini lite for awhile now with this ArduCAM setup. Everything was working perfectly, but now my esp8266 is constantly resetting.
I unplugged the ArduCAM and saw I can ran the blink script successfully, but when I try to run a script where it attempts to connect to wifi, it constantly resets.
Here is my code:
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "ssid"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = ""; // The password of the Wi-Fi network
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}
void loop() { }
When I run this, I get the following:
load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld
Exception (3):
epc1=0x40100710 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4006e989 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffb90 end: 3fffffc0 offset: 01a0
3ffffd30: feefeffe feefeffe feefeffe feefeffe
3ffffd40: feefeffe feefeffe feefeffe 3ffffef0
3ffffd50: 0000049c 0000049c 00000020 40100900
3ffffd60: feefeffe feefeffe feefeffe feefeffe
3ffffd70: 00000002 400042db 000000fd 40100b58
3ffffd80: 40004b31 00001000 000000fd 40100274
3ffffd90: 40105ae0 feefeffe feefeffe 4022da8d
3ffffda0: 40105c9d 4022db77 3ffef25c 0000049c
3ffffdb0: 000000fd 3ffffef0 3ffef25c 4022db5a
3ffffdc0: ffffff00 55aa55aa 0000000e 00000020
3ffffdd0: 00000020 00000078 00000012 aa55aa55
3ffffde0: 000000ff 4022e05a 3ffef25c 3ffef25c
3ffffdf0: 000000ff 00000119 00000119 40100640
3ffffe00: 40105c9d 00000001 3ffef26c 4022e27a
3ffffe10: 00000005 3ffef25c 000000ff 3ffffef0
3ffffe20: 3fffff10 3ffef293 0000000e 00000020
3ffffe30: 3ffef31c 3fffff51 00000001 4022e32a
3ffffe40: 3ffffef0 40239860 00000000 00000000
3ffffe50: 3ffef65c 3fffff10 3fff5594 4022e2f9
3ffffe60: 3ffef25c 4022e360 3ffe84d4 3ffe8642
3ffffe70: 40201946 3ffe8642 3ffe8663 4020189b
3ffffe80: 76696e55 69737265 6f207974 61572066
3ffffe90: 6e696873 6e6f7467 3ffffe00 40204cbc
3ffffea0: 3ffee400 00000000 3ffffe60 40204ef9
3ffffeb0: 00000f98 000001f3 000001f3 40100640
3ffffec0: 000006e8 000000dd 00000014 3ffeebc4
3ffffed0: 007a1200 44e0a632 00000000 401008cb
3ffffee0: adb5c801 fe20b34c feefeffe 00000100
3ffffef0: 76696e55 69737265 6f207974 61572066
3fffff00: 6e696873 6e6f7467 feefef00 feefeffe
3fffff10: 40203500 3ffeefcc 3ffeef4c 402035af
3fffff20: 0000001c 0001c200 00000000 00000000
3fffff30: 00000003 40203771 ffffffff 00000001
3fffff40: 40105065 00000001 3ffee35c 3ffee3d4
3fffff50: 00000000 00000001 3ffee381 00000000
3fffff60: 00000004 00000000 3ffee328 00000001
3fffff70: 0001c200 0000001c 00000000 3ffee3d4
3fffff80: 3fffdad0 3ffee328 3ffee35c 40201073
3fffff90: feefeffe feefeffe feefeffe feefeffe
3fffffa0: feefeffe 00000000 3ffee394 402024b4
3fffffb0: feefeffe feefeffe 3ffe84f0 40100b8d
<<<stack<<<
over and over and over.
I don't understand what is happening. Did I possibly short it? It couldn't have been the ArduCAM, since this was working fine already.
edit:
I found out that the Wifi.begin(ssid,password) command causes the constant reboots. When I remove this, it doesn't reboot. How can I fix this?
I think your main loop is empty. Add while(true) in the main loop function
and it´s better to set the esp in sation mode.
WiFi.mode(WIFI_STA);

ld without -lstdc++ cannot find doctest

I am working on a project under Windows and Ubuntu using CMake and CLang. On Ubuntu, I can build it OK with a shell script and could build it using Qt 5.5.1 (Creator 3.5.1). After upgrading to Qt 5.14.0 (Creator 4.11.1), there are over 1200 link errors where doctest cannot be found.
Captured compiler output:
[8/9 4.4/sec] Linking CXX executable test/test_runner
FAILED: : && /opt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-9 -g -O0 -Wall -pthread --verbose test/CMakeFiles/test_runner.dir/test_runner.cpp.o test/CMakeFiles/test_runner.dir/test.cpp.o -o test/test_runner PSCOM_LIB.a && :
clang version 9.0.0 (https://github.com/llvm-mirror/llvm c62b24f070c9a4bb1a76409e623042a740cac4cd)
Target: x86_64-unknown-linux-gnu
...
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test/test_runner /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/opt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/../lib -L/lib -L/usr/lib test/CMakeFiles/test_runner.dir/test_runner.cpp.o test/CMakeFiles/test_runner.dir/test.cpp.o PSCOM_LIB.a -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o
test/CMakeFiles/test_runner.dir/test_runner.cpp.o: In function `doctest::detail::rawMemoryToString(void const*, unsigned int)':
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2853: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)'
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2854: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2854: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::_Setfill<char>)'
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2854: undefined reference to `std::ostream::operator<<(std::ios_base& (*)(std::ios_base&))'
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2856: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::_Setw)'
/home/me/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2856: undefined reference to `std::ostream::operator<<(unsigned int)'
and hundreds of similar errors in several files.
The shell script produces the following output.
"/usr/bin/ld" ... -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc ...
I have no idea why -lstdc++ is added or not but assume that it identifies the required doctest library. Is there an option that can be added to CMakeList.txt to correct this issue?

Why "http.Get()" method is throwing fatal exception in go?

I am trying to use the following method:
response,err:=http.Get("https://support.microsoft.com")
It is working as expected. But when I call it with "https://samsung.com", it is throwing fatal exception that I can not handle.
A code sample:
package main
import (
"fmt"
"net/http"
)
func main() {
_, err := http.Get("http://support.microsoft.com")
if err != nil {
fmt.Println(err)
}
}
and here is the error:
panic: cipher.NewCBCEncrypter: IV length must equal block size
goroutine 55 [running]:
crypto/cipher.NewCBCEncrypter(0x7c7680, 0xc0001cd0b0, 0xc0000c03c8, 0x10, 0x20, 0x0, 0x0)
C:/Go/src/crypto/cipher/cbc.go:47 +0x139
crypto/tls.cipherAES(0xc0000c0388, 0x20, 0x60, 0xc0000c03c8, 0x10, 0x20, 0x0, 0x20, 0xc00008c156)
C:/Go/src/crypto/tls/cipher_suites.go:139 +0xe2
crypto/tls.(*clientHandshakeState).establishKeys(0xc0001dfdc8, 0x0, 0x0)
C:/Go/src/crypto/tls/handshake_client.go:625 +0x20c
crypto/tls.(*clientHandshakeState).handshake(0xc0001dfdc8, 0xc0000b7200, 0x0)
C:/Go/src/crypto/tls/handshake_client.go:402 +0x426
crypto/tls.(*Conn).clientHandshake(0xc00003dc00, 0x0, 0x0)
C:/Go/src/crypto/tls/handshake_client.go:208 +0x2d4
crypto/tls.(*Conn).Handshake(0xc00003dc00, 0x0, 0x0)
C:/Go/src/crypto/tls/conn.go:1343 +0xf6
net/http.(*persistConn).addTLS.func2(0x0, 0xc00003dc00, 0xc0000cc7d0, 0xc000093da0)
C:/Go/src/net/http/transport.go:1190 +0x49
created by net/http.(*persistConn).addTLS
C:/Go/src/net/http/transport.go:1186 +0x1b2
i just fixed my problem by updating go from 1.12.4 to 1.12.5.
thanks to #Markus-W-Mahlberg

Realm 1.0.1 iOS obj-c compilation error

I updated my Realm for iOS Obj-C from 0.98 to 1.0.1
but now we're getting these error during compilation:
undef: __ZN5realm4util23PlatformSpecificCondVarC1Ev undef:
__ZN5realm4util23PlatformSpecificCondVarD1Ev undef: __ZNK5realm13TableViewBase16maximum_datetimeEmPm undef: __ZNK5realm5Table16maximum_datetimeEmPm undef: __ZNK5realm11StringIndex3getEmRNSt3__15arrayIcLm8EEE undef: __ZN5realm5Table12set_datetimeEmmNS_8DateTimeE undef: __ZN5realm9Allocator10do_reallocEmPKcmm undef: __ZNK5realm5Table16minimum_datetimeEmPm undef: __ZN5realm5QueryC1ERKNS_5TableERKNS_4util8bind_ptrINS_8LinkViewEEE undef: __ZNK5realm13TableViewBase16minimum_datetimeEmPm undef:
__ZNK5realm5Table12get_datetimeEmm undef: __ZN5realm14LinkListColumn19unregister_linkviewERKNS_8LinkViewE Undefined symbols for architecture x86_64:
"realm::util::PlatformSpecificCondVar::PlatformSpecificCondVar()",
referenced from:
realm::SharedGroup::SharedGroup(realm::Replication&, realm::SharedGroup::DurabilityLevel, char const*, bool) in
libRealm.a(shared_realm.o)
"realm::util::PlatformSpecificCondVar::~PlatformSpecificCondVar()",
referenced from:
realm::SharedGroup::SharedGroup(realm::Replication&, realm::SharedGroup::DurabilityLevel, char const*, bool) in
libRealm.a(shared_realm.o)
"realm::TableViewBase::maximum_datetime(unsigned long, unsigned long*)
const", referenced from:
auto realm::Results::max(unsigned long)::$_3::operator()(realm::TableView const&)
const in libRealm.a(results.o)
"realm::Table::maximum_datetime(unsigned long, unsigned long*) const",
referenced from:
auto realm::Results::max(unsigned long)::$_3::operator()(realm::Table const&) const in
libRealm.a(results.o) "realm::StringIndex::get(unsigned long,
std::__1::array&) const", referenced from:
void realm::StringIndex::set(unsigned long, realm::null) in libRealm.a(RLMArray.o)
void realm::StringIndex::erase(unsigned long, bool) in libRealm.a(RLMArray.o)
void realm::StringIndex::erase(unsigned long, bool) in libRealm.a(RLMArray.o)
void realm::StringIndex::erase(unsigned long, bool) in libRealm.a(RLMArray.o)
void realm::StringIndex::set(unsigned long, long long) in libRealm.a(RLMQueryUtil.o)
"realm::Table::set_datetime(unsigned long, unsigned long,
realm::DateTime)", referenced from:
realm::RowFuncs >::set_datetime(unsigned long, realm::DateTime) in libRealm.a(RLMAccessor.o)
copy_property_values(realm::Property const&, realm::Property const&, realm::Table&) in libRealm.a(object_store.o)
"realm::Allocator::do_realloc(unsigned long, char const*, unsigned
long, unsigned long)", referenced from:
vtable for realm::Allocator in libRealm.a(RLMArray.o) "realm::Table::minimum_datetime(unsigned long, unsigned long*) const",
referenced from:
auto realm::Results::min(unsigned long)::$_7::operator()(realm::Table const&) const in
libRealm.a(results.o) "realm::Query::Query(realm::Table const&,
realm::util::bind_ptr const&)", referenced from:
realm::Table::where(realm::util::bind_ptr const&) in libRealm.a(RLMArrayLinkView.o)
"realm::TableViewBase::minimum_datetime(unsigned long, unsigned long*)
const", referenced from:
auto realm::Results::min(unsigned long)::$_7::operator()(realm::TableView const&)
const in libRealm.a(results.o) "realm::Table::get_datetime(unsigned
long, unsigned long) const", referenced from:
realm::RowFuncs >::get_datetime(unsigned long) const in libRealm.a(RLMAccessor.o)
copy_property_values(realm::Property const&, realm::Property const&, realm::Table&) in libRealm.a(object_store.o)
"realm::LinkListColumn::unregister_linkview(realm::LinkView const&)",
referenced from:
realm::LinkView::~LinkView() in libRealm.a(RLMArray.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I'm using cocoapods to install it. Thanks!
I ended up downgrading the cocoapods to 0.39.0
and did this
rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
pod install
This works for now.

Generic keyboard emulation using Arduino Leonardo

I am trying to use an Arduino Leonardo for keyboard emulation since that is one of its advertised features. I have been playing with the Leonardo and wrote a very simple sketch based off the Blink example.
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
// The setup routine runs once when you press reset:
void setup()
{
// Initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// The loop routine runs over and over again forever:
void loop()
{
delay(5000); // Wait for five seconds
digitalWrite(led, HIGH); // Turn the LED on (HIGH is the voltage level)
delay(100); // Wait for a secondA
digitalWrite(led, LOW); // Turn the LED off by making the voltage LOW
Keyboard.write('A'); // Write an A using keyboard emulator
}
Now this example works great on my Windows XP machine. It is recognized as a generic HID keyboard and will type an 'A' every five seconds.
The targeted environment is running DOS so to my knowledge I need to get the Arduino Leonardo recognized by the BIOS on this machine, which it is not and it does not type the 'A' in DOS.
I have been making modifications to the USB device descriptor of the Leonardo, trying to make it match a Dell L100 as much as possible. The modifications I've made haven't helped, and I suspect it is because the Leonardo is a composite device which exposes the serial communication, keyboard emulation, and mouse emulation on the same USB port. The source code for the USB descriptors/configuration is available to be edited and is located at:
Arduino_Installation\hardware\arduino\cores\arduino\HID.cpp
Arduino_Installation\hardware\arduino\cores\arduino\USBDesc.h
Arduino_Installation\hardware\arduino\cores\arduino\USBCore.h
Arduino_Installation\hardware\arduino\cores\arduino\USBCore.cpp
The following is a dump from USB Device Viewer for the Leonardo:
[Port3] : USB Composite Device
---===>Device Information<===---
English product name: "Arduino Leonardo"
ConnectionStatus:
Current Config Value: 0x01 -> Device Bus Speed: Full
Device Address: 0x03
Open Pipes: 4
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0010 = 0x10 bytes
bInterval: 0x40
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x02 -> Direction: OUT - EndpointID: 2
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x83 -> Direction: IN - EndpointID: 3
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x84 -> Direction: IN - EndpointID: 4
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x01
===>Device Descriptor<===
bLength: 0x12
bDescriptorType: 0x01
bcdUSB: 0x0110
bDeviceClass: 0x00
*!*ERROR: device class should be Multi-interface Function 0xEF
When IAD descriptor is used
bDeviceSubClass: 0x00
*!*ERROR: device SubClass should be USB Common Sub Class 2
When IAD descriptor is used
bDeviceProtocol: 0x00
*!*ERROR: device Protocol should be USB IAD Protocol 1
When IAD descriptor is used
bMaxPacketSize0: 0x40 = (64) Bytes
idVendor: 0x2341 = Vendor ID not listed with USB.org as of 03-19-2008
idProduct: 0x8036
bcdDevice: 0x0100
iManufacturer: 0x01
English (United States) "Arduino LLC"
iProduct: 0x02
English (United States) "Arduino Leonardo"
iSerialNumber: 0x00
bNumConfigurations: 0x01
===>Configuration Descriptor<===
bLength: 0x09
bDescriptorType: 0x02
wTotalLength: 0x0064 -> Validated
bNumInterfaces: 0x03
bConfigurationValue: 0x01
iConfiguration: 0x00
bmAttributes: 0x80 -> Bus Powered
MaxPower: 0xFA = 500 mA
===>IAD Descriptor<===
bLength: 0x08
bDescriptorType: 0x0B
bFirstInterface: 0x00
bInterfaceCount: 0x02
bFunctionClass: 0x02 -> This is Communications (CDC Control) USB Device Interface Class
bFunctionSubClass: 0x01
bFunctionProtocol: 0x01
iFunction: 0x00
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x00
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x02 -> This is Communications (CDC Control) USB Device Interface Class
bInterfaceSubClass: 0x01
bInterfaceProtocol: 0x00
CAUTION: This may be an invalid bInterfaceProtocol
iInterface: 0x00
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 00 10 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 01 01 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x04
bDescriptorType: 0x24
04 24 02 06
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 06 00 01
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0010 = 0x10 bytes
bInterval: 0x40
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x01
bAlternateSetting: 0x00
bNumEndpoints: 0x02
bInterfaceClass: 0x0A -> This is a CDC Data USB Device Interface Class
bInterfaceSubClass: 0x01
bInterfaceProtocol: 0x00
CAUTION: This may be an invalid bInterfaceProtocol
iInterface: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x02 -> Direction: OUT - EndpointID: 2
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x83 -> Direction: IN - EndpointID: 3
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x02
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x03 -> HID Interface Class
bInterfaceSubClass: 0x01
bInterfaceProtocol: 0x00
CAUTION: This may be an invalid bInterfaceProtocol
iInterface: 0x00
===>HID Descriptor<===
bLength: 0x09
bDescriptorType: 0x21
bcdHID: 0x0101
bCountryCode: 0x00
bNumDescriptors: 0x01
bDescriptorType: 0x22
wDescriptorLength: 0x0065
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x84 -> Direction: IN - EndpointID: 4
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x01
How could I get this Leonardo recognized by a BIOS as a generic keyboard?
Arduino does not support the boot protocol. I have started using Teensy (which is Arduino compatible), and it works pretty well.
I might be mistaken, but if you want your device to be recognized during boot, its bInterfaceSubClass should be 0x01 (boot device subclass).
In source files, as you have pointed out, sub class is set to 0x00 everywhere.
You may try to set the subclass in all usages of the D_INTERFACE macro from file USBCore.h to 0x01.
I'm not an Arduino user. I was only once playing with HID keyboard emulation on AVR using V-USB. You can try to find detailed information about usb descriptors at USB.org in documentation. But it's quite a pile of pages to read.
Here is part od HID descriptor dump of my keyboard, notice values in Interface Descriptor:
Bus 005 Device 002: ID 046d:c30e Logitech, Inc. UltraX Keyboard (Y-BL49)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x046d Logitech, Inc.
idProduct 0xc30e UltraX Keyboard (Y-BL49)
bcdDevice 1.80
iManufacturer 1 Logitech
iProduct 2 HID compliant keyboard
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 59
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 1 Keyboard
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 62
The dump was made using "lsusb -v" as root under Linux.

Resources