Ejemplo n.º 1
0
bool rch_push_data_block(rch_t *rch, data_block_t *data_blk)
{
    if (!data_frame_push_data_block(rch->data_fr, data_blk)) {
        LOG(DBG, "RCH: block fail");
        return false;
    }

    if (data_frame_blocks(rch->data_fr) != 1) {
        LOG(WTF, "block lenght != 1");
        return false;
    }

    uint8_t data[(92 + 7) / 8];
    const int size = data_frame_get_bytes(rch->data_fr, data);
    if (size != 64) {
        LOG(WTF, "invalid frame lenght");
        return false;
    }

    if (!check_fcs(data, size)) {
        LOG(DBG, "invalid FCS");
        return false;
    }

    rch->rch_data.naddrs = 0;
    for (int i = 0; i < ARRAY_LEN(rch->rch_data.addrs); ++i) {
        addr_parse(&rch->rch_data.addrs[rch->rch_data.naddrs], data + 2*i, 0);
        if (!addr_is_tti_no_st(&rch->rch_data.addrs[rch->rch_data.naddrs], true)) {
            ++rch->rch_data.naddrs;
        }
    }

    return true;
}
Ejemplo n.º 2
0
/*Reads the next packet from pcap_next() and validates the FCS. */
unsigned char *next_packet(struct pcap_pkthdr *header)
{
	const unsigned char *packet = NULL;
	struct pcap_pkthdr *pkt_header;
	static int warning_shown = 0;
	int status;

	/* Loop until we get a valid packet, or until we run out of packets */
	while((status = pcap_next_ex(get_handle(), &pkt_header, &packet)) == 1 || !status)
	{
		if(!status) continue; /* timeout */

		memcpy(header, pkt_header, sizeof(*header));

		if(get_validate_fcs() && !check_fcs(packet, header->len)) {
			if(!warning_shown)
				cprintf(INFO, "[!] Found packet with bad FCS, skipping...\n");
			warning_shown = 1;
			continue;
		}

		break;
	}

	return (void*)packet;
}
Ejemplo n.º 3
0
/*Reads the next packet from pcap_next() and validates the FCS. */
const u_char *next_packet(struct pcap_pkthdr *header)
{
    const u_char *packet = NULL;

    /* Loop until we get a valid packet, or until we run out of packets */
#ifdef __APPLE__
    struct pcap_pkthdr *pkt_header = NULL;
    int status = 1;
    while ((status = pcap_next_ex(get_handle(), &pkt_header, &packet)) == 1 || status == 0) // status == 0 indicates timeout
#else
    while((packet = pcap_next(get_handle(), header)) != NULL)
#endif
    {

#ifdef __APPLE__
      if (status == 0) continue;
      memcpy(header, pkt_header, sizeof(*header));
#endif
        
        if(get_validate_fcs())
        {
            if(check_fcs(packet, header->len))
            {
                break;
            }
            else
            {
#ifndef __APPLE__
                cprintf(INFO, "[!] Found packet with bad FCS, skipping...\n");
#endif
            }
        }
        else
        {
            break;
        }
    }

    return packet;
}