[Hackrf-dev] Fill iSerial in the usb descriptor

bon at elektron.ikp.physik.tu-darmstadt.de bon at elektron.ikp.physik.tu-darmstadt.de
Sun Jan 19 10:10:22 EST 2014


Hello,

appended patch fills iSerial in the usb device descriptor. This allows to
distinguish multiple hackrf devices already in the libusb open phase.

Feel free to use.

Bye
--
Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------

>From b65085a81230a28309c25ca7282050188637b2df Mon Sep 17 00:00:00 2001

From: Uwe Bonnes <bon at elektron.ikp.physik.tu-darmstadt.de>
Date: Sun, 19 Jan 2014 16:01:57 +0100
Subject: hackrf_usb: Fill iSerial in the USB descriptor.

Serial Number Byte 2 is exored with byte 0, byte 3 exored with 1 and the hex
nibbles are printed as hex characters.
---
firmware/hackrf_usb/hackrf_usb.c | 38 ++++++++++++++++++++++++++++++++++++
firmware/hackrf_usb/usb_descriptor.c | 6 ++++--
2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c
index 0f452f5..1e75fd5 100644
--- a/firmware/hackrf_usb/hackrf_usb.c
+++ b/firmware/hackrf_usb/hackrf_usb.c
@@ -959,10 +959,48 @@ void sgpio_isr() {
usb_bulk_buffer_offset = (usb_bulk_buffer_offset + 32) & usb_bulk_buffer_mask;
}

+uint8_t usb_descriptor_string_serial_number[] = {
+ 36, // bLength
+ USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0
+};
+
+static uint8_t bin_to_hex(uint8_t data) {
+ if (data < 10)
+ return '0' + data;
+ else
+ return 'A' + (data & 0xf);
+}
+
+static void serial_no_init(void) {
+ iap_cmd_res_t iap_cmd_res;
+ /* Read IAP Serial Number Identification */
+ iap_cmd_res.cmd_param.command_code = IAP_CMD_READ_SERIAL_NO;
+ iap_cmd_call(&iap_cmd_res);
+ if(iap_cmd_res.status_res.status_ret != CMD_SUCCESS)
+ memset(usb_descriptor_string_serial_number, 0,
+ sizeof(usb_descriptor_string_serial_number));
+ else {
+ int i;
+ uint8_t *target = usb_descriptor_string_serial_number + 2;
+ uint32_t data = iap_cmd_res.status_res.iap_result[0] ^
+ iap_cmd_res.status_res.iap_result[2];
+ for (i = 0; i < 8; i++, target = target + 2)
+ *target = bin_to_hex((data >> (i * 4)) & 0xf);
+ data = iap_cmd_res.status_res.iap_result[1] ^
+ iap_cmd_res.status_res.iap_result[3];
+ for (i = 0; i < 8; i++, target = target + 2)
+ *target = bin_to_hex((data >> (i * 4)) & 0xf);
+ }
+}
+
int main(void) {
const uint32_t ifreq = 2600000000U;

pin_setup();
+ serial_no_init();
enable_1v8_power();
#ifdef HACKRF_ONE
enable_rf_power();
diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c
index e27218b..ef320dd 100644
--- a/firmware/hackrf_usb/usb_descriptor.c
+++ b/firmware/hackrf_usb/usb_descriptor.c
@@ -50,7 +50,7 @@ uint8_t usb_descriptor_device[] = {
USB_WORD(0x0100), // bcdDevice
0x01, // iManufacturer
0x02, // iProduct
- 0x00, // iSerialNumber
+ 0x03, // iSerialNumber
0x01 // bNumConfigurations
};

@@ -181,10 +181,12 @@ uint8_t usb_descriptor_string_product[] = {
'F', 0x00,
};

+extern uint8_t usb_descriptor_string_serial_number[];
+
uint8_t* const usb_descriptor_strings[] = {
usb_descriptor_string_languages,
usb_descriptor_string_manufacturer,
usb_descriptor_string_product,
-
+ usb_descriptor_string_serial_number,
0, // TERMINATOR
};
--
1.8.4



More information about the HackRF-dev mailing list