<commit_before>/*
 * This file is part of libfreespace.
 *
 * Copyright (c) 2009 Hillcrest Laboratories, Inc.
 *
 * libfreespace is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "freespace_discoveryDetail.h"
#include "freespace_deviceMgr.h"
#include <strsafe.h>
#include <malloc.h>

/**
 * A specific usage available for a given FreespaceDeviceAPI.
 */
struct FreespaceDeviceUsageAPI {
    USAGE    usage_;
    USAGE    usagePage_;
};

/**
 * Figure out which API to use depending on the reported
 * Freespace version.
 */
struct FreespaceDeviceAPI {
    // Set of devices with this version.
    uint16_t idVendor_;
    uint16_t idProduct_;
    int      usageCount_;
	int      hVer_; // HID messaging protocol used for a particular product ID
    struct FreespaceDeviceUsageAPI usages_[FREESPACE_HANDLE_COUNT_MAX];
    const char* name_;
};

/*
 * Define the devices recognized by libfreespace.
 * Naming convention:
 *   UserMeaningfulName vN (XXXX)
 *   N = USB interface version number
 *   XXXX = Advertised interfaces:
 *      M = Mouse
 *      K = Keyboard
 *      C = Consumer page
 *      V = Joined multi-axis and vendor-specific
 *      A = Separate multi-axis and vendor-specific (deprecated)
 */
static const struct FreespaceDeviceAPI deviceAPITable[] = {
    { 0x1d5a, 0xc001, 2, 1, {{4, 0xff01}, {8, 1}}, "Piranha"},
    { 0x1d5a, 0xc002, 1, 0, {{0, 0},      {0, 0}}, "Piranha bootloader"},
    { 0x1d5a, 0xc003, 2, 1, {{4, 0xff01}, {8, 1}}, "Piranha factory test dongle"},
    { 0x1d5a, 0xc004, 1, 1, {{0, 0},      {0, 0}}, "Piranha sniffer dongle"},
    { 0x1d5a, 0xc005, 2, 1, {{4, 0xff01}, {8, 1}}, "FSRK STM32F10x eval board (E)"},
    { 0x1d5a, 0xc006, 1, 0, {{0, 0},      {0, 0}}, "Cortex Bootloader"},
    { 0x1d5a, 0xc007, 2, 1, {{4, 0xff01}, {8, 1}}, "FSRK Gen4 Dongle"},
    { 0x1d5a, 0xc008, 2, 1, {{4, 0xff01}, {8, 1}}, "SPI to USB adapter board v0"},
    { 0x1d5a, 0xc009, 2, 1, {{4, 0xff01}, {8, 1}}, "USB RF Transceiver v0"},
    { 0x1d5a, 0xc00a, 2, 1, {{4, 0xff01}, {8, 1}}, "Coprocessor to USB adapter v1 (MA)"},
    { 0x1d5a, 0xc00b, 2, 1, {{4, 0xff01}, {8, 1}}, "USB RF Transceiver v1 (MKCA)"},
    { 0x1d5a, 0xc00c, 2, 1, {{4, 0xff01}, {8, 1}}, "SPI to USB adapter v1 (MA)"},
    { 0x1d5a, 0xc010, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MV)"},
    { 0x1d5a, 0xc011, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MCV)"},
    { 0x1d5a, 0xc012, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MKV)"},
    { 0x1d5a, 0xc013, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MKCV)"},
    { 0x1d5a, 0xc020, 1, 1, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v1 (MV)"},
    { 0x1d5a, 0xc021, 1, 1, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v1 (V)"},
    { 0x1d5a, 0xc030, 1, 1, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v1 (MV)"},
    { 0x1d5a, 0xc031, 1, 1, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v1 (V)"},
    { 0x1d5a, 0xc040, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MV)"},
    { 0x1d5a, 0xc041, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MCV)"},
    { 0x1d5a, 0xc042, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MKV)"},
    { 0x1d5a, 0xc043, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MKCV)"},
    { 0x1d5a, 0xc050, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (MV)"},
    { 0x1d5a, 0xc051, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (V)"},
    { 0x1d5a, 0xc052, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (MKCV)"},
    { 0x1d5a, 0xc060, 1, 2, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v2 (MV)"},
    { 0x1d5a, 0xc061, 1, 2, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v2 (V)"},
};


/*
 * Copy a wchar string.
 * @param input The string to copy.
 * @return The copied string which must be freed externally when no longer needed.
 */
static WCHAR* dupeWCharString(const WCHAR* input) {
    int mallocStrLen = lstrlen(input) + 1;
    WCHAR* out = (WCHAR*) malloc(sizeof(WCHAR) * mallocStrLen);
    if (out != NULL) {
        StringCchCopy(out, mallocStrLen, input);
    }
    return out;<commit_msg>Added vendor IDs for Bluetooth modules.<commit_after>/*
 * This file is part of libfreespace.
 *
 * Copyright (c) 2009 Hillcrest Laboratories, Inc.
 *
 * libfreespace is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "freespace_discoveryDetail.h"
#include "freespace_deviceMgr.h"
#include <strsafe.h>
#include <malloc.h>

/**
 * A specific usage available for a given FreespaceDeviceAPI.
 */
struct FreespaceDeviceUsageAPI {
    USAGE    usage_;
    USAGE    usagePage_;
};

/**
 * Figure out which API to use depending on the reported
 * Freespace version.
 */
struct FreespaceDeviceAPI {
    // Set of devices with this version.
    uint16_t idVendor_;
    uint16_t idProduct_;
    int      usageCount_;
	int      hVer_; // HID messaging protocol used for a particular product ID
    struct FreespaceDeviceUsageAPI usages_[FREESPACE_HANDLE_COUNT_MAX];
    const char* name_;
};

/*
 * Define the devices recognized by libfreespace.
 * Naming convention:
 *   UserMeaningfulName vN (XXXX)
 *   N = USB interface version number
 *   XXXX = Advertised interfaces:
 *      M = Mouse
 *      K = Keyboard
 *      C = Consumer page
 *      V = Joined multi-axis and vendor-specific
 *      A = Separate multi-axis and vendor-specific (deprecated)
 */
static const struct FreespaceDeviceAPI deviceAPITable[] = {
    { 0x1d5a, 0xc001, 2, 1, {{4, 0xff01}, {8, 1}}, "Piranha"},
    { 0x1d5a, 0xc002, 1, 0, {{0, 0},      {0, 0}}, "Piranha bootloader"},
    { 0x1d5a, 0xc003, 2, 1, {{4, 0xff01}, {8, 1}}, "Piranha factory test dongle"},
    { 0x1d5a, 0xc004, 1, 1, {{0, 0},      {0, 0}}, "Piranha sniffer dongle"},
    { 0x1d5a, 0xc005, 2, 1, {{4, 0xff01}, {8, 1}}, "FSRK STM32F10x eval board (E)"},
    { 0x1d5a, 0xc006, 1, 0, {{0, 0},      {0, 0}}, "Cortex Bootloader"},
    { 0x1d5a, 0xc007, 2, 1, {{4, 0xff01}, {8, 1}}, "FSRK Gen4 Dongle"},
    { 0x1d5a, 0xc008, 2, 1, {{4, 0xff01}, {8, 1}}, "SPI to USB adapter board v0"},
    { 0x1d5a, 0xc009, 2, 1, {{4, 0xff01}, {8, 1}}, "USB RF Transceiver v0"},
    { 0x1d5a, 0xc00a, 2, 1, {{4, 0xff01}, {8, 1}}, "Coprocessor to USB adapter v1 (MA)"},
    { 0x1d5a, 0xc00b, 2, 1, {{4, 0xff01}, {8, 1}}, "USB RF Transceiver v1 (MKCA)"},
    { 0x1d5a, 0xc00c, 2, 1, {{4, 0xff01}, {8, 1}}, "SPI to USB adapter v1 (MA)"},
    { 0x1d5a, 0xc010, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MV)"},
    { 0x1d5a, 0xc011, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MCV)"},
    { 0x1d5a, 0xc012, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MKV)"},
    { 0x1d5a, 0xc013, 1, 1, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v1 (MKCV)"},
    { 0x1d5a, 0xc020, 1, 1, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v1 (MV)"},
    { 0x1d5a, 0xc021, 1, 1, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v1 (V)"},
    { 0x1d5a, 0xc030, 1, 1, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v1 (MV)"},
    { 0x1d5a, 0xc031, 1, 1, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v1 (V)"},
    { 0x1d5a, 0xc040, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MV)"},
    { 0x1d5a, 0xc041, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MCV)"},
    { 0x1d5a, 0xc042, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MKV)"},
    { 0x1d5a, 0xc043, 1, 2, {{4, 0xff01}, {0, 0}}, "USB RF Transceiver v2 (MKCV)"},
    { 0x1d5a, 0xc050, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (MV)"},
    { 0x1d5a, 0xc051, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (V)"},
    { 0x1d5a, 0xc052, 1, 2, {{4, 0xff01}, {0, 0}}, "SPI to USB adapter v2 (MKCV)"},
    { 0x1d5a, 0xc060, 1, 2, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v2 (MV)"},
    { 0x1d5a, 0xc061, 1, 2, {{4, 0xff01}, {0, 0}}, "Coprocessor to USB adapter v2 (V)"},
    { 0x1d5a, 0xc070, 1, 2, {{4, 0xff01}, {0, 0}}, "Bluetooth v2 (MV)"},
    { 0x1d5a, 0xc071, 1, 2, {{4, 0xff01}, {0, 0}}, "Bluetooth v2 (MCV)"},
    { 0x1d5a, 0xc022, 1, 2, {{4, 0xff01}, {0, 0}}, "Bluetooth v2 (MKV)"},
    { 0x1d5a, 0xc073, 1, 2, {{4, 0xff01}, {0, 0}}, "Bluetooth v2 (MKCV)"},
};


/*
 * Copy a wchar string.
 * @param input The string to copy.
 * @return The copied string which must be freed externally when no longer needed.
 */
static WCHAR* dupeWCharString(const WCHAR* input) {
    int mallocStrLen = lstrlen(input) + 1;
    WCHAR* out = (WCHAR*) malloc(sizeof(WCHAR) * mallocStrLen);
    if (out != NULL) {
        StringCchCopy(out, mallocStrLen, input);
    }
    return out;
{'fraction_non_alphanumeric': 0.16724348534201955, 'fraction_numerical': 0.10321661237785017, 'mean_word_length': 3.447713897691263, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4312660', 'n_tokens_mistral': 4546, 'n_tokens_neox': 3901, 'n_words': 1354}