Пример #1
0
int client_disconnect(rcp_session* session)
{
	rcp_packet discon_req;

	init_rcp_header(&discon_req, session->session_id, RCP_COMMAND_CONF_DISCONNECT_PRIMITIVE, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_P_OCTET);

	discon_req.payload_length = 8;

	discon_req.payload[0] = 0x01; // connection disconnected
	discon_req.payload[1] = 0x01; // normal termination

	memcpy(discon_req.payload + 4, &con.ctrl_addr.sin_addr.s_addr, 4);

	rcp_packet* discon_resp = rcp_command(&discon_req);
	if (discon_resp == NULL)
		goto error;

	tlog_hex(TLOG_DEBUG, "client disconnect response", discon_resp->payload, discon_resp->payload_length);

	return 0;

error:
	TL_ERROR("client_disconnect()");
	return -1;
}
Пример #2
0
int request_sps_pps(rcp_session* session, int coder, unsigned char* data, int *len)
{
	rcp_packet req;
	*len = 0;

	init_rcp_header(&req, session->session_id, RCP_COMMAND_CONF_ENC_GET_SPS_AND_PPS, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_P_OCTET);

	req.numeric_descriptor = coder;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	TL_INFO("resp action : %d", resp->action);
	tlog_hex(TLOG_DEBUG, "sps_pps_resp", resp->payload, resp->payload_length);

	memcpy(data, resp->payload, resp->payload_length);
	*len = resp->payload_length;

	return 0;

error:
	TL_ERROR("request_sps_pps()");
	return -1;
}
Пример #3
0
int client_register(int user_level, const char* password, int type, int mode)
{
	con.user_level = user_level;
	strcpy(con.password, password);

	rcp_packet reg_req;

	init_rcp_header(&reg_req, 0, RCP_COMMAND_CONF_RCP_CLIENT_REGISTRATION, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_P_OCTET);

	char pphrase[MAX_PASSPHRASE_LEN];
	int plen;
	int res = generate_passphrase(mode, con.user_level, con.password, pphrase, &plen);
	if (res == -1)
		goto error;

	tlog_hex(TLOG_DEBUG, "passphrase", pphrase, plen);

	unsigned short tmp16;
	reg_req.payload[0] = type;
	reg_req.payload[1] = 0;
	tmp16 = htons(0);
	memcpy(reg_req.payload+2, &tmp16, 2);
	reg_req.payload[4] = mode;
	reg_req.payload[5] = plen;
	tmp16 = htons(1);
	memcpy(reg_req.payload+6, &tmp16, 2);
	tmp16 = htons(0xffff);
	memcpy(reg_req.payload+8, &tmp16, 2);
	memcpy(reg_req.payload+10, pphrase, plen);
	//cl_reg.payload[plen+10] = 0;
	reg_req.payload_length = plen + 10;

	//tlog_hex("client register payload", cl_reg.payload, cl_reg.payload_length);

	rcp_packet* reg_resp = rcp_command(&reg_req);
	if (reg_resp == NULL)
		goto error;

	tlog_hex(TLOG_DEBUG, "client register response", reg_resp->payload, reg_resp->payload_length);
	if (reg_resp->payload[0] == 0)
		goto error;

	con.user_level = reg_resp->payload[1];
	con.client_id = ntohs(*(unsigned short*)(reg_resp->payload+2));

	return 0;

error:
	TL_ERROR("client_register()");
	return -1;
}
Пример #4
0
int keep_alive(rcp_session* session)
{
	rcp_packet alive_req;

	init_rcp_header(&alive_req, session->session_id, RCP_COMMAND_CONF_RCP_CONNECTIONS_ALIVE, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_F_FLAG);

	rcp_packet* alive_resp = rcp_command(&alive_req);
	if (alive_resp == NULL)
		goto error;

	return ntohl(*(unsigned int*)alive_resp->payload);

error:
	TL_ERROR("keep_alive()");
	return -1;
}
Пример #5
0
int read_client_registration()
{
	rcp_packet reg_req;

	init_rcp_header(&reg_req, 0, RCP_COMMAND_CONF_RCP_CLIENT_REGISTRATION, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_P_OCTET);

	rcp_packet* reg_resp = rcp_command(&reg_req);
	if (reg_resp == NULL)
		goto error;

	return 0;

error:
	TL_ERROR("read_client_registration()");
	return -1;
}
Пример #6
0
int get_audio_stat()
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_AUDIO_ON_OFF, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_F_FLAG);
	req.numeric_descriptor = 0;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	return resp->payload[0];

error:
	TL_ERROR("get_audio_stat()");
	return -1;
}
Пример #7
0
int request_intraframe(rcp_session* session)
{
	rcp_packet req;

	init_rcp_header(&req, session->session_id, RCP_COMMAND_CONF_MPEG4_INTRA_FRAME_REQUEST, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_T_DWORD);

	memcpy(req.payload, (char*)&session->session_id, 4);

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	return 0;

error:
	TL_ERROR("request_intraframe()");
	return -1;
}
Пример #8
0
int get_md5_random(unsigned char* md5)
{
	rcp_packet md5_req;

	init_rcp_header(&md5_req, 0, RCP_COMMAND_CONF_RCP_REG_MD5_RANDOM, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_P_STRING);

	rcp_packet* md5_resp = rcp_command(&md5_req);
	if (md5_resp == NULL)
		goto error;

	TL_DEBUG("payload len = %d", md5_resp->payload_length);
	memcpy(md5, md5_resp->payload, md5_resp->payload_length);

	return 0;

error:
	TL_ERROR("get_md5_random()");
	return -1;
}
Пример #9
0
int get_audio_input_level(int line)
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_AUDIO_INPUT_LEVEL, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_T_DWORD);
	req.numeric_descriptor = line;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	tlog_hex(TLOG_INFO, "audio input level", resp->payload, resp->payload_length);

	return ntohl(*resp->payload);

error:
	TL_ERROR("get_audio_input_level()");
	return -1;
}
Пример #10
0
int set_audio_stat(int on_off)
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_AUDIO_ON_OFF, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_F_FLAG);
	req.numeric_descriptor = 0;
	req.payload[0] = on_off;
	req.payload_length = 1;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	return 0;

error:
	TL_ERROR("set_audio_stat()");
	return -1;
}
Пример #11
0
int set_audio_input_peek(int line, int peek)
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_AUDIO_INPUT_PEEK, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_T_DWORD);
	req.numeric_descriptor = line;
	*(unsigned long*)req.payload = htonl(peek);
	req.payload_length = 4;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	tlog_hex(TLOG_INFO, "audio input peek", resp->payload, resp->payload_length);

	return ntohl(*resp->payload);

error:
	TL_ERROR("set_max_audio_input_peek()");
	return -1;
}
Пример #12
0
int set_mic_level(int line, int level)
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_AUDIO_MIC_LEVEL, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_T_DWORD);
	req.numeric_descriptor = line;
	*(unsigned long*)req.payload = htonl(level);
	req.payload_length = 4;

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	tlog_hex(TLOG_INFO, "audio mic level", resp->payload, resp->payload_length);

	return ntohl(*resp->payload);

error:
	TL_ERROR("set_mic_level()");
	return -1;
}
Пример #13
0
int client_unregister()
{
	rcp_packet unreg_req;

	init_rcp_header(&unreg_req, 0, RCP_COMMAND_CONF_RCP_CLIENT_UNREGISTER, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_P_OCTET);

	rcp_packet* unreg_resp = rcp_command(&unreg_req);
	if (unreg_resp == NULL)
		goto error;

	int unregister_result = unreg_resp->payload[0];
	if (unregister_result != 1)
	{
		TL_ERROR("unregister not successful");
		return -1;
	}
	else
		return 0;

error:
	TL_ERROR("client_unregister()");
	return -1;
}
Пример #14
0
int client_connect(rcp_session* session, int method, int media, int flags, rcp_media_descriptor* desc)
{
	rcp_packet con_req;

	init_rcp_header(&con_req, 0, RCP_COMMAND_CONF_CONNECT_PRIMITIVE, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_P_OCTET);

	int len = 0;
	char* mdesc = con_req.payload;

	unsigned short tmp16;
	mdesc[0] = method;
	mdesc[1] = media;
	mdesc[2] = 0;
	mdesc[3] = flags;
	mdesc[4] = mdesc[5] = mdesc[6] = mdesc[7] = 0;

	mdesc[8] = desc->encapsulation_protocol;
	mdesc[9] = desc->substitude_connection | (desc->relative_addressing << 1);
	tmp16 = htons(desc->mta_port);
	memcpy(mdesc+10, &tmp16, 2);
	memcpy(mdesc+12, &desc->mta_ip, 4);
	mdesc[16] = desc->coder;
	mdesc[17] = desc->line;
	tmp16 = htons(desc->coding);
	memcpy(mdesc+24, &tmp16, 2);
	tmp16 = htons(desc->resolution);
	memcpy(mdesc+26, &tmp16, 2);
	mdesc[28] = 0;
	mdesc[29] = 0;
	tmp16 = htons(1000);
	memcpy(mdesc+30, &tmp16, 2);

	mdesc += 32;
	len += 32;

	con_req.payload_length = len;

	rcp_packet* con_resp = rcp_command(&con_req);
	if (con_resp == NULL)
	{
		printf("con_resp == NULL\n");
		goto error;
	}

	TL_INFO("%s", connect_stat_str(con_resp->payload[2]));
	if (con_resp->payload[2] != 1)
	{
		printf("con_resp->payload[2] != 1\n");
		goto error;
	}

	session->session_id = con_resp->session_id;
	TL_DEBUG("session id = %d - %d", con_resp->session_id, session->session_id);
	tlog_hex(TLOG_DEBUG, "client connection resp", con_resp->payload, con_resp->payload_length);

	desc->coder = con_resp->payload[16];
	desc->line = con_resp->payload[17];
	desc->coding = ntohs(*(unsigned short*)&con_resp->payload[24]);
	desc->resolution = ntohs(*(unsigned short*)&con_resp->payload[26]);

	return 0;

error:
	TL_ERROR("client_connect()");
	return -1;
}
Пример #15
0
int get_capability_list(cap_list* caps)
{
	rcp_packet req;

	init_rcp_header(&req, 0, RCP_COMMAND_CONF_CAPABILITY_LIST, RCP_COMMAND_MODE_READ, RCP_DATA_TYPE_P_OCTET);

	rcp_packet* resp = rcp_command(&req);
	if (resp == NULL)
		goto error;

	//tlog_hex(TLOG_INFO, "cap list response", resp->payload, resp->payload_length);

	caps->version = ntohs(*(unsigned short*)(resp->payload + 2));
	caps->section_count = ntohs(*(unsigned short*)(resp->payload + 4));
	caps->sections = malloc(sizeof(cap_section) * caps->section_count);
	unsigned char* pos = resp->payload + 6;
	for (int i=0; i<caps->section_count; i++)
	{
		caps->sections[i].section_type = ntohs(*(unsigned short*)pos);
		pos += 2;
		caps->sections[i].section_size = ntohs(*(unsigned short*)pos);
		pos += 2;
		caps->sections[i].n_elems = ntohs(*(unsigned short*)pos);
		pos += 2;
		caps->sections[i].elements = malloc(sizeof(cap_element) * caps->sections[i].n_elems);
		for (int j=0; j<caps->sections[i].n_elems; j++)
		{
			caps->sections[i].elements[j].element_type = ntohs(*(unsigned short*)pos);
			pos += 2;
			switch (caps->sections[i].section_type)
			{
				case CAP_SECTION_TYPE_VIDEO:
					caps->sections[i].elements[j].identifier = ntohs(*(unsigned short*)pos);
					pos += 2;
					caps->sections[i].elements[j].compression = ntohs(*(unsigned short*)pos);
					pos += 2;
					caps->sections[i].elements[j].input_number = ntohs(*(unsigned short*)pos);
					pos += 2;
					caps->sections[i].elements[j].resolution = ntohs(*(unsigned short*)pos);
					pos += 2;
				break;
				case CAP_SECTION_TYPE_AUDIO:
					caps->sections[i].elements[j].identifier = ntohs(*(unsigned short*)pos);
					pos += 2;
					caps->sections[i].elements[j].compression = ntohs(*(unsigned short*)pos);
					pos += 2;
				break;
				case CAP_SECTION_TYPE_IO:
				case CAP_SECTION_TYPE_SERIAL:
					caps->sections[i].elements[j].identifier = ntohs(*(unsigned short*)pos);
					pos += 2;
				break;
				case CAP_SECTION_TYPE_CAMDATA:
					caps->sections[i].elements[j].input_number = ntohs(*(unsigned short*)pos);
					pos += 2;
				break;
			}
		}
	}

	return 0;

error:
	TL_ERROR("capability_list()");
	return -1;
}