/*  *********************************************************************
    *  ASTRIS - Remote JTAG probe
    *
    *  Support for SWD probes            File: astris_api.h
    *
    *  SWD Probe USB IDs and related information is defined here.
    *
    *********************************************************************
    *
    *  Copyright (C) 2020 Apple, Inc. All rights reserved.
    *
    *  This document is the property of Apple Inc.
    *  It is considered confidential and proprietary.
    *
    *  This document may not be reproduced or transmitted in any form,
    *  in whole or in part, without the express written permission of
    *  Apple Inc.
    ********************************************************************* */
#ifndef astris_probes_h
#define astris_probes_h

#include <IOKit/usb/IOUSBLib.h>

typedef enum {
    kAxProbeInvalid = 0,
    kAxProbeUSBEmbedded,
    kAxProbeUSBExternal,
    kAxProbeNetwork,
    kAxProbeKIS,
} SWDProbeType;

enum {
    kAxPrdMiniSWD   = 0x160f,
    kAxPrdKong      = 0x1611,
    kAxPrdKanzi     = 0x1621,
    kAxPrdFlamingo  = 0x1633,
    kAxPrdChimp     = 0x162c,
    kAxPrdPoodle    = 0x1642,
    kAxPrdParrot    = 0x8601,
    kAxPrdKoko      = 0x164c,
    kAxPrdKoba      = 0x168b,
    kAxPrdKIS       = 0x1881,
    kAxPrdHIDBridge = 0x1640,
    kAxPrdGordo     = 0xffff,
};

enum {
    kAxPrdHubA = 0x1009,
    kAxPrdHubB = 0x100a,
    kAxPrdHubC = 0x100c,
    kAxPrdHubD = 0x162e,
    kAxPrdHubE = 0x164e,
    kAxPrdHubF = 0x168f,
};

enum {
    kAxHubAIdx,
    kAxHubBIdx,
    kAxHubCIdx,
    kAxHubDIdx,
    kAxHubEIdx,
    kAxHubFIdx,
};

typedef struct {
    UInt16 VID;
    UInt16 PID;
} AxProbeUSBHub_t;

typedef struct {
    UInt16                       VID;
    UInt16                       PID;
    const char *const            desc;
    int                          name_id;           // -1 if the device does not support name_id
    const char *const            hub_name;
    const AxProbeUSBHub_t *const hub;
    SWDProbeType                 probe_type;
} AxProbeUSBDevice_t;

#if ASTRIS_PROBE_DATA_INTIALIZE == 1

static const AxProbeUSBHub_t AxHubList[] = {
    {kAppleVendorID, kAxPrdHubA},
    {kAppleVendorID, kAxPrdHubB},
    {kAppleVendorID, kAxPrdHubC},
    {kAppleVendorID, kAxPrdHubD},
    {kAppleVendorID, kAxPrdHubE},
    {kAppleVendorID, kAxPrdHubF},
    {0}
};

static const AxProbeUSBDevice_t g_astrisProbeTable[] = {
    {kAppleVendorID, kAxPrdMiniSWD,   "GorillaSWD",   -1, NULL,        NULL,                     kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdKong,      "KongSWD",      6,  "Kong",      NULL,                     kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdKanzi,     "KanziSWD",     6,  "Kanzi",     &(AxHubList[kAxHubCIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdFlamingo,  "Flamingo",     -1, NULL,        NULL,                     kAxProbeNetwork    },
    {kAppleVendorID, kAxPrdChimp,     "ChimpSWD",     6,  "Chimp",     &(AxHubList[kAxHubDIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdPoodle,    "PoodleSWD",    6,  "Poodle",    &(AxHubList[kAxHubCIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdKoba,      "KobaSWD",      6,  "Koba",      &(AxHubList[kAxHubCIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdParrot,    "ParrotSWD",    6,  "Parrot",    NULL,                     kAxProbeUSBEmbedded},
    {kAppleVendorID, kAxPrdKoko,      "Koko",         6,  "Koko Hub",  &(AxHubList[kAxHubEIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdGordo,     "Gordo",        6,  "Gordo",     &(AxHubList[kAxHubFIdx]), kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdHIDBridge, "HIDBridgeSWD", 6,  "HIDBridge", NULL,                     kAxProbeUSBExternal},
    {kAppleVendorID, kAxPrdKIS,       "KIS",          6,  NULL,        NULL,                     kAxProbeKIS        },
    {0}
};
#endif // ASTRIS_PROBE_DATA_INITIALIZE

#endif /* astris_probes_h */
