Ejemplo n.º 1
0
bool object_put(struct client *cli)
{
	const char *user = cli->user;
	uint64_t content_len = le64_to_cpu(cli->creq.data_len);
	enum chunk_errcode err;

	if (!user)
		return cli_err(cli, che_AccessDenied, true);

	cli->out_ce = objcache_get_dirty(&chunkd_srv.actives,
					 cli->key, cli->key_len);
	if (!cli->out_ce)
		return cli_err(cli, che_InternalError, true);

	cli->out_bo = fs_obj_new(cli->table_id, cli->key, cli->key_len,
				 content_len, &err);
	if (!cli->out_bo)
		return cli_err(cli, err, true);

	SHA1_Init(&cli->out_hash);
	cli->out_len = content_len;
	cli->out_user = strdup(user);

	if (!cli->out_len)
		return object_put_end(cli);

	cli->state = evt_data_in;

	return true;
}
Ejemplo n.º 2
0
bool object_get(struct client *cli, bool want_body)
{
	int rc;
	enum chunk_errcode err = che_InternalError;
	struct backend_obj *obj;
	struct chunksrv_resp_get *get_resp = NULL;

	get_resp = calloc(1, sizeof(*get_resp));
	if (!get_resp) {
		cli->state = evt_dispose;
		return true;
	}

	resp_init_req(&get_resp->resp, &cli->creq);

	cli->in_obj = obj = fs_obj_open(cli->table_id, cli->user, cli->key,
					cli->key_len, &err);
	if (!obj) {
		free(get_resp);
		return cli_err(cli, err, true);
	}

	cli->in_len = obj->size;

	get_resp->resp.data_len = cpu_to_le64(obj->size);
	memcpy(get_resp->resp.hash, obj->hash, sizeof(obj->hash));
	get_resp->mtime = cpu_to_le64(obj->mtime);

	rc = cli_writeq(cli, get_resp, sizeof(*get_resp), cli_cb_free, get_resp);
	if (rc) {
		free(get_resp);
		return true;
	}

	if (!want_body) {
		cli_in_end(cli);

		goto start_write;
	}

	if (!cli->in_len) {
		applog(LOG_INFO, "zero-sized object");
		cli_in_end(cli);
		goto start_write;
	}

	if (!object_read_bytes(cli)) {
		cli_in_end(cli);
		return cli_err(cli, err, false);
	}

start_write:
	return cli_write_start(cli);
}
Ejemplo n.º 3
0
static int handle_params(struct cli_state *s, int argc, char **argv, bool is_tx)
{
    int i, status;
    char *val;
    char file_mode[3];

    struct common_cfg *common;

    if (is_tx) {
        strcpy(file_mode, "r");
        common = &s->rxtx_data->tx.common;
    } else {
        strcpy(file_mode, "w");
        common = &s->rxtx_data->rx.common;
    }

    for(i = 2; i < argc; i++) {
        val = strchr(argv[i], '=');
        if (!val) {
            cli_err(s, argv[0],
                    "No value provided for parameter \"%s\"", argv[i]);

            return CMD_RET_INVPARAM;
        }

        *val++ = '\0';

        if (!strcasecmp(RXTX_PARAM_FILE, argv[i])) {
            status = set_sample_file_path(common, val);
        } else if (!strcasecmp(RXTX_PARAM_FILEFORMAT, argv[i])) {
            common->file_fmt = str2fmt(val);
            if (common->file_fmt == RXTX_FMT_INVALID) {
                cli_err(s, argv[0], "Invalid format provided (%s)", val);
                return CMD_RET_INVPARAM;
            }
        } else {
            if (is_tx) {
                status = handle_tx_param(s, argv[i], val);
                if (status)
                    return status;
            } else {
                status = handle_rx_param(s, argv[i], val);
                if (status)
                    return status;
            }
        }
    }

    return 0;
}
Ejemplo n.º 4
0
int parse_cmdline(int argc, char **argv, struct params *p, struct cli_state *s)
{
    int i;
    int status = 0;
    char *sep;

    memset(p, 0, sizeof(*p));
    memset(p->serial, '0', BLADERF_SERIAL_LENGTH - 1);
    p->type = BLADERF_IMAGE_TYPE_INVALID;

    assert(argc >= 2);
    for (i = 1; i < argc && status == 0; i++) {


        /* Check for input file */
        sep = strchr(argv[i], '=');
        if (!sep) {
            if (p->img_file) {
                cli_err(s, argv[0],
                        "Only one image file parameter is permitted.");
                status = CMD_RET_INVPARAM;
            } else {
                p->img_file = interactive_expand_path(argv[i]);
            }
        } else {
            *sep = '\0';
            sep++;
            status = handle_param(argv[i], sep, p, s, argv[0]);
        }
    }

    if (status == 0) {
        if (!p->img_file) {
            cli_err(s, argv[0], "An image file parameter is required.");
            status = CMD_RET_INVPARAM;
        } else if (p->type == BLADERF_IMAGE_TYPE_RAW &&
                !(p->override_address || p->max_length == 0)) {
            cli_err(s, argv[0],
                    "An address and a length are required for type=raw.");
            status = CMD_RET_INVPARAM;
        } else if (argc > 2 && !p->data_file) {
            cli_err(s, argv[0],
                    "A data input file is required when creating an image.");
            status = CMD_RET_INVPARAM;
        }
    }

    return status;
}
Ejemplo n.º 5
0
static int load_fx3(struct cli_state *s, char *file)
{
    char *expanded_path;
    int cmd_status = 0;
    int lib_status;

    if ((expanded_path = interactive_expand_path(file)) == NULL) {
        cli_err(s, "Unable to expand firmware file path: \"%s\"", file);
        cmd_status = CMD_RET_INVPARAM;
    } else {
        printf("Flashing firmware from %s...\n", expanded_path);
        lib_status = bladerf_flash_firmware(s->dev, expanded_path);

        if (lib_status < 0) {
            s->last_lib_error = lib_status;
            cmd_status = CMD_RET_LIBBLADERF;
        } else {
            printf("Done. Cycle power on the device.\n");
        }

        free(expanded_path);
    }

    return cmd_status;
}
Ejemplo n.º 6
0
static int load_fpga(struct cli_state *s, char *file)
{
    char *expanded_path;
    int cmd_status = 0;
    int lib_status;

    if ((expanded_path = interactive_expand_path(file)) == NULL) {
        cli_err(s, "Unable to expand FPGA file path: \"%s\"", file);
        cmd_status = CMD_RET_INVPARAM;
    } else {
        printf("Loading fpga from %s...\n", expanded_path);
        lib_status = bladerf_load_fpga(s->dev, expanded_path);

        if (lib_status < 0) {
            s->last_lib_error = lib_status;
            cmd_status = CMD_RET_LIBBLADERF;
        } else {
            printf("Done.\n");
        }

        free(expanded_path);
    }

    return cmd_status;
}
Ejemplo n.º 7
0
static bool stat_root(struct client *cli)
{
	GList *content = NULL;
	char *str;
	bool rcb;

	if (asprintf(&str,
		     "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"
		     "<html>\r\n"
		     " <head> <title>Status</title> </head>\r\n"
		     " <body>\r\n") < 0)
		goto out_err;
	content = g_list_append(content, str);

	if (!stat_status(cli, content))
		goto out_err;
	if (!stor_status(cli, content))
		goto out_err;
	if (!rep_status(cli, content))
		goto out_err;

	if (asprintf(&str,
		     " </body>\r\n"
		     "</html>\r\n") < 0)
		goto out_err;
	content = g_list_append(content, str);

	rcb = cli_resp_html(cli, 200, content);
	g_list_free(content);
	return rcb;

out_err:
	strlist_free(content);
	return cli_err(cli, InternalError);
}
Ejemplo n.º 8
0
int rxtx_cmd_start_check(struct cli_state *s, struct rxtx_data *rxtx,
                         const char *argv0)
{
    int status = CLI_RET_UNKNOWN;
    bool have_file;

    if (rxtx_get_state(rxtx) != RXTX_STATE_IDLE) {
        return CLI_RET_STATE;
    } else {
        MUTEX_LOCK(&rxtx->file_mgmt.file_meta_lock);
        have_file = (rxtx->file_mgmt.path != NULL);
        MUTEX_UNLOCK(&rxtx->file_mgmt.file_meta_lock);

        if (!have_file) {
            cli_err(s, argv0, "File not configured\n");
            status = CLI_RET_INVPARAM;
        } else {
            status = validate_stream_params(s, rxtx, argv0);
        }

        if (status == 0) {
            check_samplerate(s, rxtx);
        }
    }

    return status;
}
Ejemplo n.º 9
0
/* Require a 10% margin on the sample rate to ensure we can keep up, and
 * warn if this margin is violated
 */
static void check_samplerate(struct cli_state *s, struct rxtx_data *rxtx)
{
    int status;
    uint64_t samplerate_min;        /* Min required sample rate */
    unsigned int samplerate_dev;    /* Device's current sample rate */
    unsigned int n_xfers, samp_per_buf;

    pthread_mutex_lock(&rxtx->data_mgmt.lock);
    n_xfers = (unsigned int)rxtx->data_mgmt.num_transfers;
    samp_per_buf = (unsigned int)rxtx->data_mgmt.samples_per_buffer;
    pthread_mutex_unlock(&rxtx->data_mgmt.lock);

    samplerate_min = (uint64_t)n_xfers * samp_per_buf;
    samplerate_min += (samplerate_min + 9) / 10;

    status = bladerf_get_sample_rate(s->dev, rxtx->module, &samplerate_dev);
    if (status < 0) {
        cli_err(s, "Error", "Failed read device's current sample rate. "
                            "Unable to perform sanity check.");
    } else if (samplerate_dev < samplerate_min) {
        if (samplerate_min <= 40000000) {
            printf("\n  Warning: The current sample rate may be too low. "
                   "For %u transfers and\n"
                   "           %u samples per buffer, a sample rate >= %"
                   PRIu64" Hz is\n           recommended to avoid timeouts.\n\n",
                   n_xfers, samp_per_buf, samplerate_min);
        } else {
            printf("\n  Warning: The current configuraion with %u transfers and"
                   "%u samples per buffer requires a sample rate above 40MHz.\n"
                   "Timeouts will likely occur with these settings.\n",
                   n_xfers, samp_per_buf);
        }
    }
}
Ejemplo n.º 10
0
bool object_del(struct client *cli)
{
	int rc;
	enum chunk_errcode err = che_InternalError;
	bool rcb;
	struct chunksrv_resp *resp = NULL;

	resp = malloc(sizeof(*resp));
	if (!resp) {
		cli->state = evt_dispose;
		return true;
	}

	resp_init_req(resp, &cli->creq);

	rcb = fs_obj_delete(cli->table_id, cli->user,
			    cli->key, cli->key_len, &err);
	if (!rcb)
		return cli_err(cli, err, true);

	rc = cli_writeq(cli, resp, sizeof(*resp), cli_cb_free, resp);
	if (rc) {
		free(resp);
		return true;
	}

	return cli_write_start(cli);
}
Ejemplo n.º 11
0
int cmd_load(struct cli_state *state, int argc, char **argv)
{
    /* Valid commands:
        load fpga <filename>
        load fx3 <filename>
    */
    int rv = CMD_RET_OK ;

    if (!cli_device_is_opened(state)) {
        return CMD_RET_NODEV;
    } else if (cli_device_is_streaming(state)) {
        return CMD_RET_BUSY;
    }

    if ( argc == 3 ) {
        if( strcasecmp( argv[1], "fpga" ) == 0 ) {
            rv = load_fpga(state, argv[2]);
        } else if( strcasecmp( argv[1], "fx3" ) == 0 ) {
            rv = load_fx3(state, argv[2]);
        } else {
            cli_err(state, argv[0],
                    "\"%s\" is not a valid programming target\n", argv[1]) ;
            rv = CMD_RET_INVPARAM;
        }
    } else {
        rv = CMD_RET_NARGS;
    }

    return rv;
}
Ejemplo n.º 12
0
static int handle_tx_param(struct cli_state *s,
                                const char *param, const char *value)
{
    bool ok = false;
    unsigned int tmp_uint;

    if (!strcasecmp(RXTX_PARAM_REPEAT, param)) {
        tmp_uint = str2uint(value, 0, UINT_MAX, &ok);
        if (ok) {
            s->rxtx_data->tx.repeat = tmp_uint;
        }

    } else if (!strcasecmp(RXTX_PARAM_REPEATDLY, param)) {
        tmp_uint = str2uint(value, 0, UINT_MAX, &ok);
        if (ok) {
            s->rxtx_data->tx.repeat_delay = tmp_uint;
        }
    }

    if (!ok) {
        cli_err(s, "tx", RXTX_ERRMSG_VALUE(param, value));
        return CMD_RET_INVPARAM;
    } else {
        return 0;
    }
}
Ejemplo n.º 13
0
/* Usage:
 *      recover <devinfo> <FX3 firmware>
 *      recover
 */
int cmd_recover(struct cli_state *state, int argc, char **argv)
{
    int status;
    const char *expanded_path;
    bool ok;
    uint8_t bus, addr;

    if (argc == 1) {
        return list_bootloader_devs(state);
    } else if (argc != 4) {
        return CMD_RET_NARGS;
    }

    bus = str2uint(argv[1], 0, UINT8_MAX, &ok);
    if (!ok) {
        cli_err(state, argv[0], "Invalid bus: %s\n", bus);
        return CMD_RET_INVPARAM;
    }

    addr = str2uint(argv[2], 0, UINT8_MAX, &ok);
    if (!ok) {
        cli_err(state, argv[0], "Invalid address: %s\n", addr);
        return CMD_RET_INVPARAM;
    }

    if ((expanded_path = interactive_expand_path(argv[3])) == NULL) {
        cli_err(state,
                "Unable to expand FX3 firmware file path: \"%s\"", argv[2]);
        return CMD_RET_INVPARAM;
    }

    status = perform_recovery(state, bus, addr, expanded_path);

    if (status == 0) {
        printf("\n");
        printf("Success! Use \"open\" to switch to this device.\n");
        printf("Note that a \"load fx3 <firmware>\" is required to "
               "write the firmware to flash.\n");
        printf("\n");
        return CMD_RET_OK;
    } else if (status == CMD_RET_NODEV) {
        printf("No devices in bootloader mode were found.\n");
        return CMD_RET_OK;
    } else {
        return status;
    }
}
Ejemplo n.º 14
0
/* Todo move to cmd_probe.c */
int cmd_probe(struct cli_state *s, int argc, char *argv[])
{
    struct bladerf_devinfo *devices = NULL;
    int n_devices, i;

    n_devices = bladerf_get_device_list(&devices);

    if (n_devices < 0) {
        if (n_devices == BLADERF_ERR_NODEV) {
            cli_err(s, argv[0], "No devices found.");
        } else {
            cli_err(s, argv[0], "Failed to probe for devices: %s",
                    bladerf_strerror(n_devices));
        }

        s->last_lib_error = n_devices;
        return CLI_RET_LIBBLADERF;
    }

    printf("\n");
    for (i = 0; i < n_devices; i++) {
        printf("    Backend:        %s\n", backend2str(devices[i].backend));
        /* printf("    Serial: 0x%016lX\n", devices[i].serial); */
        /* TODO: Fix OTP support for serial readback! */
        printf("    Serial:         %s\n", devices[i].serial);
        printf("    USB Bus:        %d\n", devices[i].usb_bus);
        printf("    USB Address:    %d\n", devices[i].usb_addr);
        /*printf("    Firmware: v%d.%d\n", devices[i].fw_ver_maj,
               devices[i].fw_ver_min);

        if (devices[i].fpga_configured) {
            printf("    FPGA: v%d.%d\n",
                    devices[i].fpga_ver_maj, devices[i].fpga_ver_min);
        } else {
            printf("    FPGA: not configured\n");
        }*/
        printf("\n");
    }

    if (devices) {
        assert(n_devices != 0);
        bladerf_free_device_list(devices);
    }

    return 0;
}
Ejemplo n.º 15
0
static int rx_cmd_config(struct cli_state *s, int argc, char **argv)
{
    int i;
    char *val;
    int status;
    struct rx_params *rx_params = s->rx->params;

    assert(argc >= 2);

    if (argc == 2) {
        rx_print_config(s->rx);
        return 0;
    }

    for (i = 2; i < argc; i++) {
        status = rxtx_handle_config_param(s, s->rx, argv[0], argv[i], &val);

        if (status < 0) {
            return status;
        } else if (status == 0) {
            if (!strcasecmp("n", argv[i])) {
                /* Configure number of samples to receive */
                unsigned int n;
                bool ok;

                n = str2uint_suffix(val, 0, UINT_MAX, rxtx_kmg_suffixes,
                                    (int)rxtx_kmg_suffixes_len, &ok);

                if (ok) {
                    pthread_mutex_lock(&s->rx->param_lock);
                    rx_params->n_samples = n;
                    pthread_mutex_unlock(&s->rx->param_lock);
                } else {
                    cli_err(s, argv[0], RXTX_ERRMSG_VALUE(argv[1], val));
                    return CMD_RET_INVPARAM;
                }

            } else {
                cli_err(s, argv[0], "Unrecognized command: %s", argv[1]);
                return CMD_RET_INVPARAM;
            }
        }
    }

    return 0;
}
Ejemplo n.º 16
0
static int write_image(struct cli_state *s, struct params *p, const char *argv0)
{
    int status;
    FILE *f;
    long data_size;
    struct bladerf_image *image = NULL;

    f = expand_and_open(p->data_file, "rb");
    if (!f) {
        return CMD_RET_FILEOP;
    }

    if (fseek(f, 0, SEEK_END) != 0) {
        status = CMD_RET_FILEOP;
        goto write_image_out;
    }

    data_size = ftell(f);
    if (data_size < 0) {
        status = CMD_RET_FILEOP;
        goto write_image_out;
    }

    if ((uint32_t)data_size > p->max_length) {
        status = CMD_RET_INVPARAM;
        cli_err(s, argv0, "The provided data file is too large for the specified flash region.");
        goto write_image_out;
    }

    if (fseek(f, 0, SEEK_SET) != 0) {
        status = CMD_RET_FILEOP;
        goto write_image_out;
    }

    image = bladerf_alloc_image(p->type, p->address, data_size);
    if (!image) {
        status = CMD_RET_MEM;
        goto write_image_out;
    }

    if (fread(image->data, 1, data_size, f) != (size_t)data_size) {
        status = CMD_RET_FILEOP;
        goto write_image_out;
    }

    memcpy(image->serial, p->serial, BLADERF_SERIAL_LENGTH - 1);

    status = bladerf_image_write(image, p->img_file);
    if (status != 0) {
        s->last_lib_error = status;
        status = CMD_RET_LIBBLADERF;
    }

write_image_out:
    fclose(f);
    bladerf_free_image(image);
    return status;
}
Ejemplo n.º 17
0
int cli_start_tasks(struct cli_state *s)
{
    int status;

    status = rxtx_startup(cli_state, BLADERF_MODULE_RX);
    if (status != 0) {
        cli_err(s, "Error", "Failed to start RX task.\n");
        return CLI_RET_UNKNOWN;
    }

    status = rxtx_startup(cli_state, BLADERF_MODULE_TX);
    if (status != 0) {
        cli_err(s, "Error", "Failed to start TX task.\n");
        return CLI_RET_UNKNOWN;
    }

    return 0;
}
Ejemplo n.º 18
0
/* Todo move to cmd_probe.c */
int cmd_probe(struct cli_state *s, int argc, char *argv[])
{
    bool error_on_no_dev = false;
    struct bladerf_devinfo *devices = NULL;
    int n_devices, i;

    n_devices = bladerf_get_device_list(&devices);

    if (argc > 1 && !strcasecmp(argv[1], "strict")) {
        error_on_no_dev = true;
    }

    if (n_devices < 0) {
        if (n_devices == BLADERF_ERR_NODEV) {
            cli_err(s, argv[0], "No devices found.\n");
            if (error_on_no_dev) {
                return CLI_RET_CMD_HANDLED;
            } else {
                return 0;
            }
        } else {
            cli_err(s, argv[0], "Failed to probe for devices: %s\n",
                    bladerf_strerror(n_devices));
            s->last_lib_error = n_devices;
            return CLI_RET_LIBBLADERF;
        }
    }

    putchar('\n');
    for (i = 0; i < n_devices; i++) {
        printf("  Backend:        %s\n", backend2str(devices[i].backend));
        printf("  Serial:         %s\n", devices[i].serial);
        printf("  USB Bus:        %d\n", devices[i].usb_bus);
        printf("  USB Address:    %d\n", devices[i].usb_addr);
        putchar('\n');
    }

    if (devices) {
        assert(n_devices != 0);
        bladerf_free_device_list(devices);
    }

    return 0;
}
Ejemplo n.º 19
0
int cmd_mimo(struct cli_state *state, int argc, char **argv)
{
    int status = 0;

    if (argc != 2) {
        return CLI_RET_NARGS;
    }

    if (!strcasecmp(argv[1], "slave")) {
        status = bladerf_si5338_write(state->dev, 6, 4);
        if (status != 0) {
            goto out;
        }

        status |= bladerf_si5338_write(state->dev, 28, 0x2b);
        if (status != 0) {
            goto out;
        }

        status |= bladerf_si5338_write(state->dev, 29, 0x28);
        if (status != 0) {
            goto out;
        }

        status |= bladerf_si5338_write(state->dev, 30, 0xa8);
        if (status != 0) {
            goto out;
        }

        printf("\n  Successfully set device to slave MIMO mode.\n\n");

    } else if (!strcmp(argv[1], "master")) {
        status |= bladerf_si5338_write(state->dev, 39, 1);
        if (status != 0) {
            goto out;
        }

        status |= bladerf_si5338_write(state->dev, 34, 0x22);
        if (status != 0) {
            goto out;
        }

        printf("\n  Successfully set device to master MIMO mode.\n\n");
    } else {
        cli_err(state, argv[0], "Invalid mode: %s\n", argv[1]);
    }

out:
    if (status != 0) {
        state->last_lib_error = status;
        status = CLI_RET_LIBBLADERF;
    }

    return status;
}
Ejemplo n.º 20
0
static int validate_config(struct cli_state *s, const char *cmd,
                            struct rxtx_data *d, bool is_tx)
{
    int status = CMD_RET_OK;
    struct common_cfg *common = is_tx ? &d->tx.common : &d->rx.common;
    bool file_path_set;

    pthread_mutex_lock(&common->file_lock);
    file_path_set = common->file_path != NULL;
    pthread_mutex_unlock(&common->file_lock);

    if (!file_path_set) {
        cli_err(s, cmd, "File parameter has not been configured");
        status = CMD_RET_INVPARAM;
    } else if (common->file_fmt == RXTX_FMT_INVALID) {
        cli_err(s, cmd, "File format parameter has not been configured");
        status = CMD_RET_INVPARAM;
    }

    return status;
}
Ejemplo n.º 21
0
static int find_device(struct cli_state *s,
                       libusb_context * context,
                       uint8_t bus, uint8_t addr,
                       libusb_device_handle **handle,
                       bool just_print)
{
    int status, i;
    libusb_device *dev, **devs;
    libusb_device *found_dev = NULL;
    ssize_t status_sz;
    size_t num_found = 0;

    status_sz = libusb_get_device_list(context, &devs);
    if (status_sz < 0) {
        cli_err(s, "Error", "libusb_get_device_list() failed: %d %s\n",
                status_sz, libusb_error_name((int)status_sz));

        return CMD_RET_UNKNOWN;
    }

    for (i = 0; (dev = devs[i]) != NULL && found_dev == NULL; i++) {

        if (just_print && is_bootloader_device(s, dev)) {
            if (num_found++ == 0) {
                printf("\n");
            }

            printf("  Bootloader @ bus=%d, addr=%d\n",
                   libusb_get_bus_number(dev), libusb_get_device_address(dev));

        } else if (is_bootloader_device(s, dev) &&
                   bus == libusb_get_bus_number(dev) &&
                   addr == libusb_get_device_address(dev)) {
            found_dev = dev;
        }
    }

    if (found_dev == NULL || (just_print && num_found == 0)) {
        s->last_lib_error =  BLADERF_ERR_NODEV;
        return CMD_RET_LIBBLADERF;
    } else if (!just_print) {
        status = libusb_open(found_dev, handle);

        if (status != 0) {
            s->last_lib_error = BLADERF_ERR_IO;
            return CMD_RET_LIBBLADERF;
        }
    }

    libusb_free_device_list(devs, 1);
    return 0;
}
Ejemplo n.º 22
0
static int tx_cmd_start(struct cli_state *s)
{
    int status = 0;

    status = rxtx_cmd_start_check(s, s->tx, "tx");

    if (status == 0) {
        /* Perform file conversion (if needed) and open input file */
        pthread_mutex_lock(&s->tx->file_mgmt.file_meta_lock);

        if (s->tx->file_mgmt.format == RXTX_FMT_CSV_SC16Q11) {
            status = tx_csv_to_sc16q11(s);

            if (status == 0) {
                printf("    Converted CSV to SC16 Q11 file and "
                        "switched to converted file.\n\n");
            }
        }

        if (status == 0) {
            pthread_mutex_lock(&s->tx->file_mgmt.file_lock);

            assert(s->tx->file_mgmt.format == RXTX_FMT_BIN_SC16Q11);
            s->tx->file_mgmt.file = fopen(s->tx->file_mgmt.path, "r");
            if (!s->tx->file_mgmt.file) {
                set_last_error(&s->tx->last_error, ETYPE_ERRNO, errno);
                status = CMD_RET_FILEOP;
            } else {
                status = 0;
            }

            pthread_mutex_unlock(&s->tx->file_mgmt.file_lock);
        }

        pthread_mutex_unlock(&s->tx->file_mgmt.file_meta_lock);

        if (status == 0) {
            rxtx_submit_request(s->tx, RXTX_TASK_REQ_START);
            status = rxtx_wait_for_state(s->tx, RXTX_STATE_RUNNING, 3000);

            /* This should never occur. If it does, there's likely a defect
             * present in the tx task */
            if (status != 0) {
                cli_err(s, "tx", "TX did not start up in the alloted time\n");
                status = CMD_RET_UNKNOWN;
            }
        }
    }

    return status;
}
Ejemplo n.º 23
0
static int parse_argv(struct cli_state *state, int argc, char **argv,
                      struct options *opt)
{
    bool ok;

    if (argc != 2 && argc != 4)
        return CMD_RET_NARGS;

    if (argc >= 2) {
        if ((opt->file = interactive_expand_path(argv[1])) == NULL) {
            cli_err(state, argv[0], "Unable to expand file path: \"%s\"",
                    argv[1]);
            return CMD_RET_INVPARAM;
        }

        opt->address = CAL_PAGE;
        opt->len = CAL_BUFFER_SIZE;
        opt->override_defaults = false;
    }

    if (argc == 4) {
        opt->address = str2uint(argv[2], 0, UINT_MAX, &ok);
        if (!ok) {
            cli_err(state, argv[0], "Invalid address provided");
            return CMD_RET_INVPARAM;
        }

        opt->len = str2uint(argv[3], 0, UINT_MAX, &ok);
        if (!ok) {
            cli_err(state, argv[0], "Invalid length provided");
            return CMD_RET_INVPARAM;
        }

        opt->override_defaults = true;
    }

    return 0;
}
Ejemplo n.º 24
0
int cmd_trigger(struct cli_state *state, int argc, char **argv)
{
    int status = 0;
    bladerf_module m;
    bladerf_trigger_signal s;

    switch (argc) {
        case 1:
            status = print_all_triggers(state);
            break;

        case 3:
        case 4:
            s = str2trigger(argv[1]);
            if (s == BLADERF_TRIGGER_INVALID) {
                cli_err(state, "Invalid trigger signal", "%s\n", argv[1]);
                return CLI_RET_INVPARAM;
            }

            m = str2module(argv[2]);
            if (m == BLADERF_MODULE_INVALID) {
                cli_err(state, "Invalid module", "%s\n", argv[2]);
                return CLI_RET_INVPARAM;
            }

            if (argc == 3) {
                status = print_trigger(state, m, s);
            } else {
                status = config_trigger(state, m, s, argv[3], argv[0]);
            }
            break;

        default:
            status = CLI_RET_NARGS;
    }

    return status;
}
Ejemplo n.º 25
0
static int tx_cmd_start(struct cli_state *s)
{
    int status = 0;

    /* Check that we're able to start up in our current state */
    status = rxtx_cmd_start_check(s, s->tx, "tx");
    if (status != 0) {
        return status;
    }

    /* Perform file conversion (if needed) and open input file */
    MUTEX_LOCK(&s->tx->file_mgmt.file_meta_lock);

    if (s->tx->file_mgmt.format == RXTX_FMT_CSV_SC16Q11) {
        status = tx_csv_to_sc16q11(s);

        if (status == 0) {
            printf("  Converted CSV to SC16 Q11 file and "
                    "switched to converted file.\n\n");
        }
    }

    if (status == 0) {
        MUTEX_LOCK(&s->tx->file_mgmt.file_lock);

        assert(s->tx->file_mgmt.format == RXTX_FMT_BIN_SC16Q11);
        status = expand_and_open(s->tx->file_mgmt.path, "rb",
                                 &s->tx->file_mgmt.file);
        MUTEX_UNLOCK(&s->tx->file_mgmt.file_lock);
    }

    MUTEX_UNLOCK(&s->tx->file_mgmt.file_meta_lock);

    if (status != 0) {
        return status;
    }

    /* Request thread to start running */
    rxtx_submit_request(s->tx, RXTX_TASK_REQ_START);
    status = rxtx_wait_for_state(s->tx, RXTX_STATE_RUNNING, 3000);

    /* This should never occur. If it does, there's likely a defect
     * present in the tx task */
    if (status != 0) {
        cli_err(s, "tx", "TX did not start up in the alloted time\n");
        status = CLI_RET_UNKNOWN;
    }

    return status;
}
Ejemplo n.º 26
0
int cmd_erase(struct cli_state *state, int argc, char **argv)
{
    int status;
    int addr, len;
    int eb_offset, n_ebs;
    bool ok;

    if (argc != 3) {
        return CLI_RET_NARGS;
    }

    eb_offset = str2uint(argv[1], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0],
                "Invalid value for \"eb_offset\" (%s)\n", argv[1]);
        return CLI_RET_INVPARAM;
    }

    n_ebs = str2uint(argv[2], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"n_ebs\" (%s)\n", argv[2]);
        return CLI_RET_INVPARAM;
    }

    addr = eb_offset;
    len  = n_ebs;

    status = bladerf_erase_flash(state->dev, addr, len);

    if (status >= 0) {
        printf("\n  Erased %d blocks at 0x%02x\n\n", len, addr);
        return CLI_RET_OK;
    } else {
        state->last_lib_error = status;
        return CLI_RET_LIBBLADERF;
    }
}
Ejemplo n.º 27
0
static int is_fpga_configured(struct cli_state *state, const char *cmd)
{
    int status;

    status = bladerf_is_fpga_configured(state->dev);
    if (status < 0) {
        cli_err(state, cmd, "Failed to determine if the FPGA is "
                            "configured. Is the FX3 programmed?");

        state->last_lib_error = status;
        status = CLI_RET_LIBBLADERF;
    }

    return status;
}
Ejemplo n.º 28
0
int cmd_erase(struct cli_state *state, int argc, char **argv)
{
    int status;
    int page_offset, n_bytes;
    bool ok;

    if (!cli_device_is_opened(state)) {
        return CMD_RET_NODEV;
    }

    if (argc != 3) {
        return CMD_RET_NARGS;
    }

    page_offset = str2uint(argv[1], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"page_offset\" (%s)", argv[1]);
        return CMD_RET_INVPARAM;
    }

    n_bytes = str2uint(argv[2], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"n_bytes\" (%s)", argv[2]);
        return CMD_RET_INVPARAM;
    }

    status = bladerf_erase_flash(state->dev, page_offset, n_bytes);

    if (status >= 0) {
        printf("Erased %d pages at %d\n", status, page_offset);
        return CMD_RET_OK;
    } else {
        state->last_lib_error = status;
        return CMD_RET_LIBBLADERF;
    }
}
Ejemplo n.º 29
0
static int set_trx_mode(struct cli_state *state, const char *trxmode)
{
    int status;

    if (!strcasecmp(trxmode, "tx")) {
        status = bladerf_xb300_set_trx(state->dev, BLADERF_XB300_TRX_TX);
    } else if (!strcasecmp(trxmode, "rx")) {
        status = bladerf_xb300_set_trx(state->dev, BLADERF_XB300_TRX_RX);
    } else {
        cli_err(state, trxmode, "Invalid TRX option.");
        status = CLI_RET_INVPARAM;
    }

    return status;
}
Ejemplo n.º 30
0
int cli_cmd_ganesha_cbk (struct cli_state *state, struct cli_cmd_word *word,
                         const char **words, int wordcount)

{
         int                     sent        =   0;
         int                     parse_error =   0;
         int                     ret         =  -1;
         rpc_clnt_procedure_t    *proc       =  NULL;
         call_frame_t            *frame      =  NULL;
         dict_t                  *options    =  NULL;
         cli_local_t             *local      =  NULL;
         char                    *op_errstr  =  NULL;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GANESHA];

        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        ret = cli_cmd_ganesha_parse (state, words, wordcount,
                                     &options, &op_errstr);
        if (ret) {
                if (op_errstr) {
                    cli_err ("%s", op_errstr);
                    GF_FREE (op_errstr);
                } else
                    cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        CLI_LOCAL_INIT (local, words, frame, options);

        if (proc->fn) {
                ret = proc->fn (frame, THIS, options);
        }

out:
        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("Setting global option failed");
        }

        CLI_STACK_DESTROY (frame);
        return ret;
}