diff --git a/DSView/res/DSLogicPlus-pgl12.bin b/DSView/res/DSLogicPlus-pgl12.bin new file mode 100644 index 00000000..e3393062 Binary files /dev/null and b/DSView/res/DSLogicPlus-pgl12.bin differ diff --git a/DSView/res/DSLogicU2Basic-pgl12.bin b/DSView/res/DSLogicU2Basic-pgl12.bin new file mode 100644 index 00000000..e3393062 Binary files /dev/null and b/DSView/res/DSLogicU2Basic-pgl12.bin differ diff --git a/libsigrok4DSL/hardware/DSL/command.h b/libsigrok4DSL/hardware/DSL/command.h index 53eef7b6..f2b4b398 100644 --- a/libsigrok4DSL/hardware/DSL/command.h +++ b/libsigrok4DSL/hardware/DSL/command.h @@ -48,6 +48,8 @@ #define bmWR_WORDWIDE (1 << 0) #define VTH_ADDR 0x78 +#define SEC_DATA_ADDR 0x75 +#define SEC_CTRL_ADDR 0x73 #define CTR1_ADDR 0x71 #define CTR0_ADDR 0x70 #define COMB_ADDR 0x68 @@ -55,6 +57,14 @@ #define ADCC_ADDR 0x48 #define HDL_VERSION_ADDR 0x04 +#define bmSECU_READY (1 << 3) +#define bmSECU_PASS (1 << 4) +#define SECU_STEPS 8 +#define SECU_START 0x0513 +#define SECU_CHECK 0x0219 +#define SECU_EEP_ADDR 0x3C00 +#define SECU_TRY_CNT 8 + #define EI2C_CTR_OFF 0x2 #define EI2C_RXR_OFF 0x3 #define EI2C_SR_OFF 0x4 diff --git a/libsigrok4DSL/hardware/DSL/dsl.c b/libsigrok4DSL/hardware/DSL/dsl.c index a07a222b..5fb85f88 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.c +++ b/libsigrok4DSL/hardware/DSL/dsl.c @@ -30,6 +30,13 @@ #undef LOG_PREFIX #define LOG_PREFIX "dsl: " +SR_PRIV int dsl_secuReset(const struct sr_dev_inst *sdi); +SR_PRIV int dsl_secuWrite(const struct sr_dev_inst *sdi, uint16_t cmd, uint16_t din); +SR_PRIV gboolean dsl_isSecuReady(const struct sr_dev_inst *sdi); +SR_PRIV gboolean dsl_isSecuPass(const struct sr_dev_inst *sdi); +SR_PRIV uint16_t dsl_secuRead(const struct sr_dev_inst *sdi); +SR_PRIV int dsl_secuCheck(const struct sr_dev_inst *sdi, uint16_t* encryption, int steps); + static const int32_t probeOptions[] = { SR_CONF_PROBE_COUPLING, SR_CONF_PROBE_VDIV, @@ -1912,6 +1919,17 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo } } + // check security + uint16_t encryption[SECU_STEPS]; + ret = dsl_wr_reg(sdi, CTR0_ADDR, bmNONE); // dessert clear + if (dsl_rd_nvm(sdi, (unsigned char *)encryption, SECU_EEP_ADDR, SECU_STEPS*2) != SR_OK) { + sr_err("Read EEPROM content failed!"); + return SR_ERR; + } + ret = dsl_secuCheck(sdi, encryption, SECU_STEPS); + if (ret != SR_OK) + sr_err("Security check failed!"); + return SR_OK; } @@ -2520,3 +2538,104 @@ SR_PRIV int sr_option_value_to_code(int config_id, const char *value, const stru return -1; } + + +/* + * security low level operations + */ +SR_PRIV int dsl_secuReset(const struct sr_dev_inst *sdi) +{ + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR, 0) != SR_OK) goto Err; + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR + 1, 0) != SR_OK) goto Err; + g_usleep(10*1000); + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR, 1) != SR_OK) goto Err; + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR + 1, 0) != SR_OK) goto Err; + + return SR_OK; +Err: + sr_err("Sent dsl_wr_reg(SEC_XXX_ADDR) command failed."); + return SR_ERR; +} + +SR_PRIV int dsl_secuWrite(const struct sr_dev_inst *sdi, uint16_t cmd, uint16_t din) +{ + if (dsl_wr_reg(sdi, SEC_DATA_ADDR, din) != SR_OK) goto Err; + if (dsl_wr_reg(sdi, SEC_DATA_ADDR + 1, (din >> 8)) != SR_OK) goto Err; + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR, cmd) != SR_OK) goto Err; + if (dsl_wr_reg(sdi, SEC_CTRL_ADDR + 1, (cmd >> 8)) != SR_OK) goto Err; + + return SR_OK; +Err: + sr_err("Sent dsl_wr_reg(SEC_XXX_ADDR) command failed."); + return SR_ERR; +} + +SR_PRIV gboolean dsl_isSecuReady(const struct sr_dev_inst *sdi) +{ + uint8_t temp; + if (dsl_rd_reg(sdi, SEC_CTRL_ADDR, &temp) != SR_OK) goto Err; + + if (temp & bmSECU_READY) + return TRUE; + else + return FALSE; +Err: + sr_err("Sent dsl_rd_reg(SEC_XXX_ADDR) command failed."); + return FALSE; +} + +SR_PRIV gboolean dsl_isSecuPass(const struct sr_dev_inst *sdi) +{ + uint8_t temp; + if (dsl_rd_reg(sdi, SEC_CTRL_ADDR, &temp) != SR_OK) goto Err; + + if (temp & bmSECU_PASS) + return TRUE; + else + return FALSE; +Err: + sr_err("Sent dsl_rd_reg(SEC_XXX_ADDR) command failed."); + return FALSE; +} + +SR_PRIV uint16_t dsl_secuRead(const struct sr_dev_inst *sdi) +{ + uint16_t sec; + if (dsl_rd_reg(sdi, SEC_DATA_ADDR + 1, (uint8_t*)&sec) != SR_OK) goto Err; + sec <<= 8; + if (dsl_rd_reg(sdi, SEC_DATA_ADDR, (uint8_t*)&sec) != SR_OK) goto Err; + + return sec; +Err: + sr_err("Sent dsl_rd_reg(SEC_XXX_ADDR) command failed."); + return 0; +} + + +/* + * security API interface + */ +SR_PRIV int dsl_secuCheck(const struct sr_dev_inst *sdi, uint16_t* encryption, int steps) +{ + int tryCnt = SECU_TRY_CNT; + + dsl_secuReset(sdi); + if (dsl_isSecuPass(sdi)) + return SR_ERR; + dsl_secuWrite(sdi, SECU_START, 0); + while(steps--) { + if (dsl_isSecuPass(sdi)) + return SR_ERR; + while(!dsl_isSecuReady(sdi)) { + if (tryCnt-- == 0) { + sr_err("Get security ready failed."); + return SR_ERR; + } + } + if (dsl_secuRead(sdi) != 0) + return SR_ERR; + dsl_secuWrite(sdi, SECU_CHECK, encryption[steps]); + } + + return SR_OK; +} diff --git a/libsigrok4DSL/hardware/DSL/dsl.h b/libsigrok4DSL/hardware/DSL/dsl.h index 9d816540..59f73a5f 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.h +++ b/libsigrok4DSL/hardware/DSL/dsl.h @@ -73,6 +73,8 @@ #define CAPS_FEATURE_LA_CH32 (1 << 11) // auto tunning vgain #define CAPS_FEATURE_AUTO_VGAIN (1 << 12) +// max 2.5v fpga threshold +#define CAPS_FEATURE_MAX25_VTH (1 << 13) /* end */ @@ -689,6 +691,60 @@ static const struct DSL_profile supported_DSLogic[] = { SR_GHZ(1)} }, + {0x2A0E, 0x0030, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic PLus", NULL, + "DSLogicPlus.fw", + "DSLogicPlus-pgl12.bin", + "DSLogicPlus-pgl12.bin", + {CAPS_MODE_LOGIC, + CAPS_FEATURE_VTH | CAPS_FEATURE_BUF | CAPS_FEATURE_MAX25_VTH, + (1 << DSL_STREAM20x16) | (1 << DSL_STREAM25x12) | (1 << DSL_STREAM50x6) | (1 << DSL_STREAM100x3) | + (1 << DSL_BUFFER100x16) | (1 << DSL_BUFFER200x8) | (1 << DSL_BUFFER400x4), + 16, + SR_MB(256), + 0, + DSL_BUFFER100x16, + 0, + samplerates400, + 0, + DSL_STREAM20x16, + SR_MHZ(1), + SR_Mn(1), + 0, + 0, + 0, + 0, + 0, + SR_MHZ(200), + SR_MHZ(400)} + }, + + {0x2A0E, 0x0031, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U2Basic", NULL, + "DSLogicU2Basic.fw", + "DSLogicU2Basic-pgl12.bin", + "DSLogicU2Basic-pgl12.bin", + {CAPS_MODE_LOGIC, + CAPS_FEATURE_VTH | CAPS_FEATURE_BUF | CAPS_FEATURE_MAX25_VTH, + (1 << DSL_STREAM20x16) | (1 << DSL_STREAM25x12) | (1 << DSL_STREAM50x6) | (1 << DSL_STREAM100x3) | + (1 << DSL_BUFFER100x16), + 16, + SR_MB(64), + 0, + DSL_BUFFER100x16, + 0, + samplerates100, + 0, + DSL_STREAM20x16, + SR_MHZ(1), + SR_Mn(1), + 0, + 0, + 0, + 0, + 0, + SR_MHZ(200), + SR_MHZ(400)} + }, + { 0, 0, LIBUSB_SPEED_UNKNOWN, 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}} };