Exemple #1
0
/**
 * \brief Pack all system commands stored in VPacket structure to the buffer
 * \param[in]	vmessage	The structure with data for message
 * \param[out]	buffer		The buffer, that will be sent to the peer.
 * \return This function return of bytes packed to the buffer.
 */
int v_pack_stream_system_commands(const struct VMessage *vmessage, char *buffer)
{
	unsigned short buffer_pos=0;
	int i=0;

	while(vmessage->sys_cmd[i].cmd.id != CMD_RESERVED_ID && i<MAX_SYSTEM_COMMAND_COUNT) {
		switch(vmessage->sys_cmd[i].cmd.id) {
		case CMD_USER_AUTH_REQUEST:
			buffer_pos += v_raw_pack_user_auth_request(&buffer[buffer_pos],
					&vmessage->sys_cmd[i].ua_req);
			break;
		case CMD_USER_AUTH_FAILURE:
			buffer_pos += v_raw_pack_user_auth_failure(&buffer[buffer_pos],
					&vmessage->sys_cmd[i].ua_fail);
			break;
		case CMD_USER_AUTH_SUCCESS:
			buffer_pos += v_raw_pack_user_auth_success(&buffer[buffer_pos],
					&vmessage->sys_cmd[i].ua_succ);
			break;
		case CMD_CHANGE_L_ID:
		case CMD_CONFIRM_L_ID:
		case CMD_CHANGE_R_ID:
		case CMD_CONFIRM_R_ID:
			buffer_pos += v_raw_pack_negotiate_cmd(&buffer[buffer_pos],
					&vmessage->sys_cmd[i].negotiate_cmd);
			break;
		}
		i++;
	}

	return buffer_pos;
}
Exemple #2
0
/**
 * \brief Pack all system commands stored in VPacket structure to the buffer.
 */
int v_pack_dgram_system_commands(const struct VPacket *vpacket, char *buffer)
{
	unsigned short buffer_pos=0;
	int i=0;

	while(vpacket->sys_cmd[i].cmd.id != CMD_RESERVED_ID && i<MAX_SYSTEM_COMMAND_COUNT) {
		switch(vpacket->sys_cmd[i].cmd.id) {
			case CMD_ACK_ID:
				buffer_pos += v_raw_pack_ack_nak_cmd(&buffer[buffer_pos],
						&vpacket->sys_cmd[i].ack_cmd);
				break;
			case CMD_NAK_ID:
				buffer_pos += v_raw_pack_ack_nak_cmd(&buffer[buffer_pos],
						&vpacket->sys_cmd[i].nak_cmd);
				break;
			case CMD_CHANGE_L_ID:
			case CMD_CONFIRM_L_ID:
			case CMD_CHANGE_R_ID:
			case CMD_CONFIRM_R_ID:
				buffer_pos += v_raw_pack_negotiate_cmd(&buffer[buffer_pos],
						&vpacket->sys_cmd[i].negotiate_cmd);
				break;
		}
		i++;
	}

	return buffer_pos;
}
Exemple #3
0
END_TEST


/**
 * \brief Test packing and unpacking of negotiate command with multiple values
 */
START_TEST ( test_pack_unpack_negotiate_cmd_multiple_values )
{
	union VSystemCommands send_sys_cmd[1], recv_sys_cmd[1];
	uint8 cmd_op_code = CMD_CONFIRM_L_ID;
	uint8 ftr_op_code = FTR_FC_ID;
	uint8 values[2] = {FC_TCP_LIKE, FC_NONE};
	char buffer[255];
	int ret, buffer_pos = 0, cmd_len;

	/* Create negotiate command */
	ret = v_add_negotiate_cmd(send_sys_cmd, 0, cmd_op_code, ftr_op_code,
			&values[0], &values[1], NULL);

	fail_unless( ret == 1,
			"Adding negotiate command failed");

	/* Pack negotiate command */
	buffer_pos += v_raw_pack_negotiate_cmd(buffer,
			&send_sys_cmd[0].negotiate_cmd);

	fail_unless( buffer_pos == 5,
			"Length of packed cmd: %d != %d",
			buffer_pos, 5);

	/* Unpack system command */
	cmd_len = v_raw_unpack_negotiate_cmd(buffer, buffer_pos,
			&recv_sys_cmd[0].negotiate_cmd);

	fail_unless( cmd_len == buffer_pos,
			"Length of packed and unpacked cmd: %d != %d",
			buffer_pos, cmd_len);
	fail_unless( recv_sys_cmd->negotiate_cmd.id == cmd_op_code,
			"Negotiate command OpCode: %d != %d",
			recv_sys_cmd->negotiate_cmd.id, cmd_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.feature == ftr_op_code,
			"Negotiate command feature: %d != %d",
			recv_sys_cmd->negotiate_cmd.feature, ftr_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.count == 2,
			"Negotiate command feature count: %d != %d",
			recv_sys_cmd->negotiate_cmd.count, 2);
	fail_unless( recv_sys_cmd->negotiate_cmd.value[0].uint8 == values[0],
			"Negotiate command value[0]: %d != %d",
			recv_sys_cmd->negotiate_cmd.value[0].uint8, values[0]);
	fail_unless( recv_sys_cmd->negotiate_cmd.value[1].uint8 == values[1],
			"Negotiate command value[1]: %d != %d",
			recv_sys_cmd->negotiate_cmd.value[1].uint8, values[1]);
}
Exemple #4
0
END_TEST


/**
 * \brief Test of packing and unpacking negotiate command with string value.
 */
START_TEST ( test_pack_unpack_negotiate_cmd_string_value )
{
	union VSystemCommands send_sys_cmd[1], recv_sys_cmd[1];
	uint8 cmd_op_code = CMD_CHANGE_R_ID;
	uint8 ftr_op_code = FTR_CLIENT_NAME;
	char string[5] = {'a', 'h', 'o', 'y', '\0'};
	char buffer[255];
	int ret, buffer_pos = 0, cmd_len;

	ret = v_add_negotiate_cmd(send_sys_cmd, 0, cmd_op_code, ftr_op_code, string, NULL);

	fail_unless( ret == 1,
			"Adding negotiate command failed");

	/* Pack negotiate command */
	buffer_pos += v_raw_pack_negotiate_cmd(buffer,
			&send_sys_cmd[0].negotiate_cmd);

	fail_unless( buffer_pos == 8,
			"Length of packed cmd: %d != %d",
			buffer_pos, 8);

	/* Unpack system command */
	cmd_len = v_raw_unpack_negotiate_cmd(buffer, buffer_pos,
			&recv_sys_cmd[0].negotiate_cmd);

	fail_unless( cmd_len == buffer_pos,
			"Length of packed and unpacked cmd: %d != %d",
			buffer_pos, cmd_len);
	fail_unless( recv_sys_cmd->negotiate_cmd.id == cmd_op_code,
			"Negotiate command OpCode: %d != %d",
			recv_sys_cmd->negotiate_cmd.id, cmd_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.feature == ftr_op_code,
			"Negotiate command feature: %d != %d",
			recv_sys_cmd->negotiate_cmd.feature, ftr_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.count == 1,
			"Negotiate command feature count: %d != %d",
			recv_sys_cmd->negotiate_cmd.count, 1);
	fail_unless( recv_sys_cmd->negotiate_cmd.value[0].string8.length == 4,
			"Negotiate command value (string length): %d != %d",
			recv_sys_cmd->negotiate_cmd.value[0].string8.length, 4);
	fail_unless( strcmp((char*)recv_sys_cmd->negotiate_cmd.value[0].string8.str, "ahoy") == 0,
			"Negotiate command value (string): %s != ahoy",
			recv_sys_cmd->negotiate_cmd.value[0].string8.str);

}
Exemple #5
0
END_TEST


/**
 * \brief Test simple packing and unpacking of negotiate command
 */
START_TEST ( test_pack_unpack_negotiate_cmd_float_value )
{
	union VSystemCommands send_sys_cmd[1], recv_sys_cmd[1];
	uint8 cmd_op_code = CMD_CHANGE_L_ID;
	uint8 ftr_op_code = FTR_FPS;
	real32 value = 60.0f;
	char buffer[255];
	int ret, buffer_pos = 0, cmd_len;

	/* Create negotiate command */
	ret = v_add_negotiate_cmd(send_sys_cmd, 0, cmd_op_code, ftr_op_code,
			&value, NULL);

	fail_unless( ret == 1,
			"Adding negotiate command failed");

	/* Pack negotiate command */
	buffer_pos += v_raw_pack_negotiate_cmd(buffer,
			&send_sys_cmd[0].negotiate_cmd);

	fail_unless( buffer_pos == 7,
			"Length of packed cmd: %d != %d",
			buffer_pos, 7);

	/* Unpack system command */
	cmd_len = v_raw_unpack_negotiate_cmd(buffer, buffer_pos,
			&recv_sys_cmd[0].negotiate_cmd);

	fail_unless( cmd_len == buffer_pos,
			"Length of packed and unpacked cmd: %d != %d",
			buffer_pos, cmd_len);
	fail_unless( recv_sys_cmd->negotiate_cmd.id == cmd_op_code,
			"Negotiate command OpCode: %d != %d",
			recv_sys_cmd->negotiate_cmd.id, cmd_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.feature == ftr_op_code,
			"Negotiate command feature: %d != %d",
			recv_sys_cmd->negotiate_cmd.feature, ftr_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.count == 1,
			"Negotiate command feature count: %d != %d",
			recv_sys_cmd->negotiate_cmd.count, 1);
	fail_unless( recv_sys_cmd->negotiate_cmd.value[0].real32 == value,
			"Negotiate command value: %d != %d",
			recv_sys_cmd->negotiate_cmd.value[0].real32, value);
}
Exemple #6
0
END_TEST


/**
 * \brief Test of packing and unpacking negotiate command with string value.
 */
START_TEST ( test_pack_unpack_negotiate_cmd_long_string_value )
{
	union VSystemCommands send_sys_cmd[1], recv_sys_cmd[1];
	uint8 cmd_op_code = CMD_CHANGE_R_ID;
	uint8 ftr_op_code = FTR_CLIENT_NAME;
	char string[470] = "Lorem ipsum dolor sit amet, consectetuer adipiscing "
			"elit. Ut enim ad minim veniam, quis nostrud exercitation ullamco "
			"laboris nisi ut aliquip ex ea commodo consequat. Nullam at arcu "
			"a est sollicitudin euismod. Fusce consectetuer risus a nunc. "
			"Cras pede libero, dapibus nec, pretium sit amet, tempor quis. "
			"Etiam dictum tincidunt diam. Nullam lectus justo, vulputate "
			"eget mollis sed, tempor sed magna. Vivamus porttitor turpis ac "
			"leo. Suspendisse sagittis ultrices augue.";
	char buffer[512];
	int ret, buffer_pos = 0, cmd_len;

	ret = v_add_negotiate_cmd(send_sys_cmd, 0, cmd_op_code, ftr_op_code, string, NULL);

	fail_unless( ret == 1,
			"Adding negotiate command failed");

	/* Pack negotiate command */
	buffer_pos += v_raw_pack_negotiate_cmd(buffer,
			&send_sys_cmd[0].negotiate_cmd);

	fail_unless( buffer_pos == 261,
			"Length of packed cmd: %d != %d",
			buffer_pos, 8);

	/* Unpack system command */
	cmd_len = v_raw_unpack_negotiate_cmd(buffer, buffer_pos,
			&recv_sys_cmd[0].negotiate_cmd);

	fail_unless( cmd_len == buffer_pos,
			"Length of packed and unpacked cmd: %d != %d",
			buffer_pos, cmd_len);
	fail_unless( recv_sys_cmd->negotiate_cmd.id == cmd_op_code,
			"Negotiate command OpCode: %d != %d",
			recv_sys_cmd->negotiate_cmd.id, cmd_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.feature == ftr_op_code,
			"Negotiate command feature: %d != %d",
			recv_sys_cmd->negotiate_cmd.feature, ftr_op_code);
	fail_unless( recv_sys_cmd->negotiate_cmd.count == 1,
			"Negotiate command feature count: %d != %d",
			recv_sys_cmd->negotiate_cmd.count, 1);
	fail_unless( recv_sys_cmd->negotiate_cmd.value[0].string8.length == 255,
			"Negotiate command value (string length): %d != %d",
			recv_sys_cmd->negotiate_cmd.value[0].string8.length, 255);
	/* Make original string 255 bytes long */
	string[255] = '\0';
	fail_unless( strncmp((char*)recv_sys_cmd->negotiate_cmd.value[0].string8.str, string, 255) == 0,
			"Negotiate command value (string): %s != %s",
			recv_sys_cmd->negotiate_cmd.value[0].string8.str,
			string);

}