]> sigrok.org Git - libsigrok.git/commitdiff
hantek-6xxx: Ignore requests to set Hantek 6022BE coupling.
authorErik Montnemery <redacted>
Thu, 18 Aug 2016 21:05:11 +0000 (23:05 +0200)
committerUwe Hermann <redacted>
Sun, 21 Aug 2016 16:54:15 +0000 (18:54 +0200)
Here's a patch to "Ignore requests to set coupling for the Hantek 6022BE",
this clears the LIBUSB errors for me.

Also in the patch:

 - There is a crash because config_list() can be called with sdi == NULL.

   This can be reproduced by doing:
     "sigrok-cli.exe --driver hantek-6xxx --show"

 - There seems to be a very unsafe loop in config_set() when setting COUPLING;
   the coupling vector is assumed to be zero terminated, but is not declared
   as such.

   Note: The same issue is present also for other hardware, at least for
   hantek-dso/api.c. The patch is only for hantek-6xxx though.

src/hardware/hantek-6xxx/api.c
src/hardware/hantek-6xxx/protocol.c
src/hardware/hantek-6xxx/protocol.h

index 57f5a28db4ace9176a9e13a412bd0b8556c7454f..55cf5fdfe91313ec3474317b1fb0894f3a678e61 100644 (file)
@@ -62,12 +62,12 @@ static const struct hantek_6xxx_profile dev_profiles[] = {
        {
                0x04b4, 0x6022, 0x04b5, 0x6022,
                "Hantek", "6022BE", "hantek-6022be.fw",
-               dc_coupling, ARRAY_SIZE(dc_coupling),
+               dc_coupling, ARRAY_SIZE(dc_coupling), FALSE,
        },
        {
                0x8102, 0x8102, 0x1D50, 0x608E,
                "Sainsmart", "DDS120", "sainsmart-dds120.fw",
-               acdc_coupling, ARRAY_SIZE(acdc_coupling),
+               acdc_coupling, ARRAY_SIZE(acdc_coupling), TRUE,
        },
        ALL_ZERO
 };
@@ -440,13 +440,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        break;
                case SR_CONF_COUPLING:
                        tmp_str = g_variant_get_string(data, NULL);
-                       for (i = 0; devc->coupling_vals[i]; i++) {
+                       for (i = 0; i < devc->coupling_tab_size; i++) {
                                if (!strcmp(tmp_str, devc->coupling_vals[i])) {
                                        devc->coupling[ch_idx] = i;
                                        break;
                                }
                        }
-                       if (devc->coupling_vals[i] == 0)
+                       if (i == devc->coupling_tab_size)
                                ret = SR_ERR_ARG;
                        break;
                default:
@@ -465,7 +465,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
        GVariant *gvar;
-       struct dev_context *devc;
+       struct dev_context *devc = NULL;
 
        if (key == SR_CONF_SCAN_OPTIONS) {
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
@@ -477,10 +477,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                return SR_OK;
        }
 
-       if (!sdi)
-               return SR_ERR_ARG;
-
-       devc = sdi->priv;
+       if (sdi)
+               devc = sdi->priv;
 
        if (!cg) {
                switch (key) {
@@ -506,6 +504,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                                devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
                        break;
                case SR_CONF_COUPLING:
+                       if (!devc)
+                               return SR_ERR_NA;
                        *data = g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
                        break;
                case SR_CONF_VDIV:
index 12a56ab9d09970589aa0fd1e25c46ed29ebc5cc2..a43f72bbb546247abcd8ce68cfce68c19478d501 100644 (file)
@@ -220,9 +220,13 @@ SR_PRIV int hantek_6xxx_update_coupling(const struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
        uint8_t coupling = 0xFF & ((devc->coupling[1] << 4) | devc->coupling[0]);
 
-       sr_dbg("update coupling 0x%x", coupling);
-
-       return write_control(sdi, COUPLING_REG, coupling);
+       if (devc->has_coupling) {
+               sr_dbg("update coupling 0x%x", coupling);
+               return write_control(sdi, COUPLING_REG, coupling);
+       } else {
+               sr_dbg("coupling not supported");
+               return SR_OK;
+       }
 }
 
 SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi)
index 0c54ec92cf4a2e2583a4644fd68edef331ebd615..c32792e3c898712d0486485e0cba5221e27080d0 100644 (file)
@@ -99,6 +99,7 @@ struct hantek_6xxx_profile {
        const char *firmware;
        const char **coupling_vals;
        uint8_t coupling_tab_size;
+       gboolean has_coupling;
 };
 
 struct dev_context {
@@ -127,6 +128,7 @@ struct dev_context {
        int coupling[NUM_CHANNELS];
        const char **coupling_vals;
        uint8_t coupling_tab_size;
+       gboolean has_coupling;
        uint64_t samplerate;
 
        uint64_t limit_msec;