Esempio n. 1
0
int Network::read_data()
{
    if (m_connection.receive(&m_input_buffer) < 0)
        return -1;
    int readed = m_input_buffer.getSize();
    if (readed == 0)
        return 0;
    m_totalReaded += readed;
    if (!m_mccp_on)
    {
        m_input_data.write(m_input_buffer.getData(), readed);
        m_totalDecompressed += readed;
    }
    else
    {
        m_mccp_data.write(m_input_buffer.getData(), readed);
        if (m_mccp_data.getSize() == 0)
            return 0;
        if (!process_mccp())
            return -2;
    }

    //OUTPUT_BYTES(m_input_data.getData(), m_input_data.getSize(), m_input_data.getSize(), "decompressed");
    while(m_input_data.getSize() > 0)
    {
        const tbyte* in = (tbyte*)m_input_data.getData();
        int in_len = m_input_data.getSize();

        bool error = false;
        int processed = processing_data(in, in_len, &error);
        if (error)
            return -1;

        if (processed == 0)      // low/no data for processing
        {
            break;
        }
        else if (processed < 0)  // truncated system data
        {
            processed = -processed;
        }
        else
        {
            if (processed == 2 && in[0] == IAC && in[1] == IAC)
                m_receive_data.write(in, 1);
            else if (processed == 2 && in[0] == IAC && in[1] == GA)
            {
                unsigned char bytes[2] = { 0x1b, 0x5c };
                m_receive_data.write(bytes, 2);
            }
            else
                m_receive_data.write(in, processed);
        }
        m_input_data.truncate(processed);
    }

    //OUTPUT_BYTES(m_input_data.getData(), m_input_data.getSize(), m_input_data.getSize(), "notprocessed");
    return 1;
}
Esempio n. 2
0
static void net_rx_thread(void)
{
	struct net_pkt *pkt;

	NET_DBG("Starting RX thread (stack %zu bytes)", sizeof(rx_stack));

	/* Starting TX side. The ordering is important here and the TX
	 * can only be started when RX side is ready to receive packets.
	 * We synchronize the startup of the device so that both RX and TX
	 * are only started fully when both are ready to receive or send
	 * data.
	 */
	net_if_init(&startup_sync);

	k_sem_take(&startup_sync, K_FOREVER);

	/* This will take the interface up and start everything. */
	net_if_post_init();

	while (1) {
#if defined(CONFIG_NET_STATISTICS) || defined(CONFIG_NET_DEBUG_CORE)
		size_t pkt_len;
#endif

		pkt = k_fifo_get(&rx_queue, K_FOREVER);

		net_analyze_stack("RX thread", rx_stack, sizeof(rx_stack));

#if defined(CONFIG_NET_STATISTICS) || defined(CONFIG_NET_DEBUG_CORE)
		pkt_len = net_pkt_get_len(pkt);
#endif
		NET_DBG("Received pkt %p len %zu", pkt, pkt_len);

		net_stats_update_bytes_recv(pkt_len);

		processing_data(pkt, false);

		net_print_statistics();
		net_pkt_print();

		k_yield();
	}
}
Esempio n. 3
0
/* Called when data needs to be sent to network */
int net_send_data(struct net_pkt *pkt)
{
	int status;

	if (!pkt || !pkt->frags) {
		return -ENODATA;
	}

	if (!net_pkt_iface(pkt)) {
		return -EINVAL;
	}

#if defined(CONFIG_NET_STATISTICS)
	switch (net_pkt_family(pkt)) {
	case AF_INET:
		net_stats_update_ipv4_sent();
		break;
	case AF_INET6:
		net_stats_update_ipv6_sent();
		break;
	}
#endif

	status = check_ip_addr(pkt);
	if (status < 0) {
		return status;
	} else if (status > 0) {
		/* Packet is destined back to us so send it directly
		 * to RX processing.
		 */
		NET_DBG("Loopback pkt %p back to us", pkt);
		processing_data(pkt, true);
		return 0;
	}

	if (net_if_send_data(net_pkt_iface(pkt), pkt) == NET_DROP) {
		return -EIO;
	}

	return 0;
}