Ejemplo n.º 1
0
/*
 * This function can be called for either T_WRITE or a free-standing
 * T_ARG_UINT, so it's called with t pointing to the first token after
 * T_WRITE, or the first T_ARG_UINT in the free-standing case.
 *
 * Returns the number of tokens eaten.
 */
static int hydrabus_mode_write(t_hydra_console *con, t_tokenline_parsed *p,
			       int t)
{
	mode_config_proto_t* p_proto = &con->mode->proto;
	uint32_t mode_status;
	unsigned int num_bytes = 0;
	int tokens_used, i;
	int count = 1;

	tokens_used = 0;

	switch(p->tokens[t]) {
	case T_ARG_TOKEN_SUFFIX_INT:
		t++;
		memcpy(&count, p->buf + p->tokens[t++], sizeof(int));
		tokens_used += 2;
	case T_ARG_UINT:
	case T_TILDE:
		tokens_used += chomp_integers(con, p, t, &num_bytes);
		break;
	case T_ARG_STRING:
		tokens_used += chomp_strings(con, p, t, &num_bytes);
		break;
	}

	if (!num_bytes)
		return 0;

	for (i = 0; i < count; i++) {
		if (p_proto->wwr == 1) {
			/* Write & Read */
			mode_status = !HYDRABUS_MODE_STATUS_OK;
			if(con->mode->exec->write_read != NULL) {
				mode_status = con->mode->exec->write_read(con,
						p_proto->buffer_tx, p_proto->buffer_rx, num_bytes);
			}

			if (mode_status != HYDRABUS_MODE_STATUS_OK)
				hydrabus_mode_write_read_error(con, mode_status);
		} else {
			/* Write only */
			mode_status = !HYDRABUS_MODE_STATUS_OK;
			if(con->mode->exec->write != NULL) {
				mode_status = con->mode->exec->write(con,
								     p_proto->buffer_tx, num_bytes);
			}
			if (mode_status != HYDRABUS_MODE_STATUS_OK)
				hydrabus_mode_write_error(con, mode_status);
		}
	}

	return tokens_used;
}
Ejemplo n.º 2
0
/*
 * This function can be called for either T_WRITE or a free-standing
 * T_ARG_INT, so it's called with t pointing to the first token after
 * T_WRITE, or the first T_ARG_INT in the free-standing case.
 *
 * Returns the number of tokens eaten.
 */
static int hydrabus_mode_write(t_hydra_console *con, t_tokenline_parsed *p,
			       int t)
{
	mode_config_proto_t* p_proto = &con->mode->proto;
	uint32_t mode_status;
	unsigned int num_bytes;
	int count, tokens_used, i;

	tokens_used = 0;
	if (p->tokens[t] == T_ARG_TOKEN_SUFFIX_INT) {
		t++;
		memcpy(&count, p->buf + p->tokens[t++], sizeof(int));
		tokens_used += 2;
	} else {
		count = 1;
	}

	if (p->tokens[t] != T_ARG_INT) {
		cprintf(con, "No bytes to write.\r\n");
		return 0;
	}

	tokens_used += chomp_integers(con, p, t, &num_bytes);
	if (!num_bytes)
		return 0;

	for (i = 0; i < count; i++) {
		if (p_proto->wwr == 1) {
			/* Write & Read */
			mode_status = !HYDRABUS_MODE_STATUS_OK;
			if(con->mode->exec->write_read != NULL) {
				mode_status = con->mode->exec->write_read(con,
						p_proto->buffer_tx, p_proto->buffer_rx, num_bytes);
			}

			if (mode_status != HYDRABUS_MODE_STATUS_OK)
				hydrabus_mode_write_read_error(con, mode_status);
		} else {
			/* Write only */
			mode_status = !HYDRABUS_MODE_STATUS_OK;
			if(con->mode->exec->write != NULL) {
				mode_status = con->mode->exec->write(con,
								     p_proto->buffer_tx, num_bytes);
			}
			if (mode_status != HYDRABUS_MODE_STATUS_OK)
				hydrabus_mode_write_error(con, mode_status);
		}
	}

	return tokens_used;
}