Beispiel #1
0
int photograph( void *pbuf, int size)
{

	unsigned long outsize;
	int ret;

	VideoStream_Enc_Reset();
	
	//printf("%d\n", h_eid);
	void * buf;
	if( 2 == index_file )
		ret = frame_encode(h_eid , pbuf+(parse.width*parse.height*3/2), &buf, &outsize);
	else
		ret = frame_encode(h_eid, pbuf, &buf, &outsize);

	if(ret == 0)
	{
		Condition_Lock( g_conMangerPh );
		g_phsize = outsize;
		Condition_Signal( &g_conMangerPh );
		Condition_Unlock( g_conMangerPh );
	}

	VideoStream_Enc_Reset();
	
	return 0;
}
Beispiel #2
0
void modem_output(uint8_t *data, size_t count)
{
    buffer_t pktbuf;
    buffer_init(&pktbuf, data, count+1);
    buffer_write_seek(&pktbuf, count * 8);

    while (buffer_read_remaining(&pktbuf))
    {
        frame_encode(&pktbuf, &g_frames);
    }
}
Beispiel #3
0
int test_frame_ctl(uint8_t key[SHAREDKEY_BYTESIZE]) {
#define	TESTBUFSIZE	4096
	int i,ret;
	ssize_t crypted_len;
	struct frame_st *crypted_frame = NULL;
	internal_msg_t *ori_frame_body;
	internal_msg_t decrypt_frame_body;

	ori_frame_body = malloc(sizeof(*ori_frame_body));
	ori_frame_body->msg_type = MSG_CTL_TYPE;
	ori_frame_body->ctl_frame_body.code = CTL_PIPELINE_OPEN;
	ori_frame_body->ctl_frame_body.arg.pipeline_open.flow_id = 1234;
	ori_frame_body->ctl_frame_body.arg.pipeline_open.max_delay_in_ms = 500;
	ori_frame_body->ctl_frame_body.arg.pipeline_open.reply_frame_flags = 1;
	ori_frame_body->ctl_frame_body.arg.pipeline_open.data = malloc(TESTBUFSIZE);
	ori_frame_body->ctl_frame_body.arg.pipeline_open.data_len = TESTBUFSIZE;
	for (i=0;i<TESTBUFSIZE;++i) {
		ori_frame_body->ctl_frame_body.arg.pipeline_open.data[i] = i%63;
	}

	printf("Original: %d bytes.\n", TESTBUFSIZE);

	crypted_len = frame_encode(&crypted_frame, ori_frame_body, FRAME_FLAG_MAKE(1, 1, 1), key);
	printf("frame_encode() = %d bytes.\n", (int)crypted_len);

	ret = frame_decode(&decrypt_frame_body, crypted_frame, key);
	printf("frame_decode() = %d bytes.\n", decrypt_frame_body.ctl_frame_body.arg.pipeline_open.data_len);

	if (memcmp(ori_frame_body->ctl_frame_body.arg.pipeline_open.data, decrypt_frame_body.ctl_frame_body.arg.pipeline_open.data, TESTBUFSIZE)==0) {
		puts("encrypt_frame_body/decrypt_frame_body OK.");
	} else {
		puts("encrypt_frame_body/decrypt_frame_body FAILed.");
	}
	printf("Original: ");
	bin_dump(stdout, ori_frame_body->ctl_frame_body.arg.pipeline_open.data, TESTBUFSIZE);
	printf("Crypted: ");
	bin_dump(stdout, crypted_frame->frame_body, crypted_len);
	printf("Derypted: ");
	bin_dump(stdout, decrypt_frame_body.ctl_frame_body.arg.pipeline_open.data, decrypt_frame_body.ctl_frame_body.arg.pipeline_open.data_len);

	free(ori_frame_body->ctl_frame_body.arg.pipeline_open.data);
	free(ori_frame_body);
	free(crypted_frame);
	return 0;
}
// Private methods
// Writes data from the transmit queue to the physical layer and sets the frames written as transmited
void DataLinkLayer::writeData() {
    for(int i = 0; i < _tx_buffer_size; i++) {
        Frame * frame = _transmitFrameList[i];
        if (!(frame->get_control_data() & CONTROL_TRANS_FRAME)) {
            uint8_t encoded_frame_size = 0;
            frame->prepare_to_transmit();
            uint8_t * encoded_frame = frame_encode(frame, &encoded_frame_size);
            frame->set_control_data(frame->get_control_data() | CONTROL_TRANS_FRAME);
            uint32_t bytes_written = _physicalLayer->write(encoded_frame, encoded_frame_size);
            if (bytes_written == 0) {
                frame->set_control_data(frame->get_control_data() & ~CONTROL_TRANS_FRAME);
            }
            PrintUtl.prints("Sent ");
            frame->print();
            free(encoded_frame);
        }
    }
}
Beispiel #5
0
int test_frame_data(uint8_t key[SHAREDKEY_BYTESIZE]) {
#define	TESTBUFSIZE	4096
	int i,ret;
	ssize_t crypted_len;
	struct frame_st *crypted_frame = NULL;
	internal_msg_t *ori_frame_body;
	internal_msg_t decrypt_frame_body;

	ori_frame_body = malloc(sizeof(*ori_frame_body));
	ori_frame_body->msg_type = 0;
	ori_frame_body->data_frame_body.flow_id = 12345;
	ori_frame_body->data_frame_body.data = malloc(TESTBUFSIZE);
	ori_frame_body->data_frame_body.data_len = TESTBUFSIZE;
	for (i=0;i<TESTBUFSIZE;++i) {
		ori_frame_body->data_frame_body.data[i] = i%63;
	}

	printf("Original: %d bytes.\n", TESTBUFSIZE);

	crypted_len = frame_encode(&crypted_frame, ori_frame_body, FRAME_FLAG_MAKE(1, 1, 1), key);
	printf("frame_encode() = %d bytes.\n", (int)crypted_len);

	ret = frame_decode(&decrypt_frame_body, crypted_frame, key);
	printf("frame_decode() = %d bytes.\n", decrypt_frame_body.data_frame_body.data_len);

	if (memcmp(ori_frame_body->data_frame_body.data, decrypt_frame_body.data_frame_body.data, TESTBUFSIZE)==0) {
		puts("encrypt_frame_body/decrypt_frame_body OK.");
	} else {
		puts("encrypt_frame_body/decrypt_frame_body FAILed.");
	}
	printf("Original: ");
	bin_dump(stdout, ori_frame_body->data_frame_body.data, TESTBUFSIZE);
	printf("Crypted: ");
	bin_dump(stdout, crypted_frame->frame_body, crypted_len);
	printf("Derypted: ");
	bin_dump(stdout, decrypt_frame_body.data_frame_body.data, decrypt_frame_body.data_frame_body.data_len);

	free(ori_frame_body->data_frame_body.data);
	free(ori_frame_body);
	free(crypted_frame);
	return 0;
}
Beispiel #6
0
int socket_end_msg_enqueue(struct socket_end_st *socket_end, int flag, internal_msg_t *msg, int plid) {
	ssize_t size;
	int ret = -1;
	struct pipeline_end_st *pe;
	struct frame_st *dst = NULL;
	struct streambuf_iov_st *iov = NULL;

	mylog(L_DEBUG, "Socket end msg send");

	dst = malloc(MSG_FRAME_MAX);
	if (dst == NULL) {
		mylog(L_ERR, "Malloc dst failed");
		goto error;
	}

	size = frame_encode(dst, MSG_FRAME_BODY_MAX, msg, flag, socket_end->shared_key);
	if (unlikely(size <= 0)) {
		mylog(L_ERR, "Frame encode failed");
		goto error;
	}

	iov = streambuf_iov_construct(dst, size);
	if (unlikely(iov == NULL)) {
		mylog(L_ERR, "Iov construct failed");
		goto error;
	}

	ret = streambuf_write_nb(socket_end->send_buffer, iov);
	if (ret == ENOMEM) {
		mylog(L_INFO, "Send buffer hard limit exceeded, se[%d] pe[%d]", socket_end->id, plid);
		if (plid >= 0) {
			pe = socket_end->pipeline_end[plid];

			if (pe->iov_recv_pending) {
				mylog(L_INFO, "Pe receive pending buffer is exist");
				pe->iov_recv_pending = streambuf_iov_merge(pe->iov_recv_pending, iov);
				if (pe->iov_recv_pending == NULL) {
					/* Should not be here */
					mylog(L_ERR, "Iov merge failed");
					abort();
				}
				streambuf_iov_free(iov);
			} else {
				pe->iov_recv_pending = iov;
			}
		}
	}

	return ret;

error:
	if (iov) {
		free(iov);
		iov = NULL;
	}
	if (dst) {
		free(dst);
		dst = NULL;
	}

	return ret;
}