Here is the whole code... Everything that is commented out doesn't really work. The only way it works is with the uint8_t buf[] = {...}; definition. Malloc/new/in function does not work. This is really strange. I have no clue what it could be and Arduino being Arduino there is no real way to debug this efficiently 
Also the effective call to sendControlPacket can be in a function or not. That does not seem to matter. Only the origin of the buf.
Code:
#include "USBHost_t36.h"
// Variables
USBHost myusb;
USBHIDParser hid(myusb);
bool hid_active = false;
void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB HID Vive Tracker Control");
myusb.begin();
}
void loop()
{
myusb.Task();
if (Serial.available()) {
int ch = Serial.read(); // get the first char.
while (Serial.read() != -1) ;
if (hid_active) {
if (ch == 's') {
Serial.println("____Sending B3 packet.");
/*
uint8_t buf[] = {
0xB3, // 0xB3
3, // Length
2, // Host type: 2: Phone 3: Accessory
1, // Reserved
1 // Reserved
};*/
/*uint8_t* buf = (uint8_t*) malloc(5 * sizeof(uint8_t));
//uint8_t* buf = new uint8_t[5];
if (buf == NULL) {
Serial.println("memory alloc failed");
}
buf[0] = 0xB3;
buf[1] = 3;
buf[2] = 2;
buf[3] = 1;
buf[4] = 1;*/
//bool result = hid.sendControlPacket(0x21, 0x09, 0x0300, 2, 5, buf);
//bool result = send_b3_packet(hid, buf);
//Serial.printf("Result: %s\n", result ? "true" : "false");
} else if (ch == 'b') {
Serial.println("Sending B4 packet.");
bool result = send_b4_packet(hid);
Serial.printf("Result: %s\n", result ? "true" : "false");
}
} else {
Serial.println("Device not connected.");
}
}
if (hid != hid_active) {
if (hid_active) {
Serial.printf("*** HID Device disconnected ***\n");
hid_active = false;
} else {
Serial.printf("*** HID Device %x:%x connected ***\n", hid.idVendor(), hid.idProduct());
hid_active = true;
const uint8_t *psz = hid.manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = hid.product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = hid.serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
delay(1000);
Serial.println("Sending B3 packet.");
uint8_t buf[] = {
0xB3, // 0xB3
3, // Length
3, // Host type: 2: Phone 3: Accessory
1, // Reserved
1 // Reserved
};
bool result = send_b3_packet(hid, buf);
}
}
}
bool send_b3_packet(USBHIDParser& hid_parser, void* buf2) {
/*uint8_t buf[] = {
0xB3, // 0xB3
3, // Length
2, // Host type: 2: Phone 3: Accessory
1, // Reserved
1 // Reserved
};*/
return hid_parser.sendControlPacket(0x21, 0x09, 0x0300, 2, 5, buf2);
};