Beispiel #1
0
static int
commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
                     int *err, gchar **err_info)
{
    commview_header_t cv_hdr;
    struct tm tm;

    if(!commview_read_header(&cv_hdr, fh, err, err_info))
        return FALSE;

    switch(cv_hdr.flags & FLAGS_MEDIUM) {

    case MEDIUM_ETHERNET :
        phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
        phdr->pseudo_header.eth.fcs_len = -1; /* Unknown */
        break;

    case MEDIUM_WIFI :
        phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
        phdr->pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */
        phdr->pseudo_header.ieee_802_11.channel = cv_hdr.channel;
        phdr->pseudo_header.ieee_802_11.data_rate =
            cv_hdr.rate | (cv_hdr.direction << 8);
        phdr->pseudo_header.ieee_802_11.signal_level = cv_hdr.signal_level_percent;
        break;

    case MEDIUM_TOKEN_RING :
        phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
        break;

    default :
        *err = WTAP_ERR_BAD_FILE;
        *err_info = g_strdup_printf("commview: unsupported encap: %u",
                                    cv_hdr.flags & FLAGS_MEDIUM);
        return FALSE;
    }

    tm.tm_year = cv_hdr.year - 1900;
    tm.tm_mon = cv_hdr.month - 1;
    tm.tm_mday = cv_hdr.day;
    tm.tm_hour = cv_hdr.hours;
    tm.tm_min = cv_hdr.minutes;
    tm.tm_sec = cv_hdr.seconds;
    tm.tm_isdst = -1;

    phdr->rec_type = REC_TYPE_PACKET;
    phdr->presence_flags = WTAP_HAS_TS;

    phdr->len = cv_hdr.data_len;
    phdr->caplen = cv_hdr.data_len;

    phdr->ts.secs = mktime(&tm);
    phdr->ts.nsecs = cv_hdr.usecs * 1000;

    return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}
Beispiel #2
0
int commview_open(wtap *wth, int *err, gchar **err_info)
{
	commview_header_t cv_hdr;

	if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) {
		if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
			return -1;
		return 0;
	}

	/* If any of these fields do not match what we expect, bail out. */
	if(cv_hdr.version != 0 ||
	   cv_hdr.year < 1970 || cv_hdr.year >= 2038 ||
	   cv_hdr.month < 1 || cv_hdr.month > 12 ||
	   cv_hdr.day < 1 || cv_hdr.day > 31 ||
	   cv_hdr.hours > 23 ||
	   cv_hdr.minutes > 59 ||
	   cv_hdr.seconds > 60 ||
	   cv_hdr.signal_level_percent > 100 ||
	   (cv_hdr.flags & FLAGS_RESERVED) != 0 ||
	   ((cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_ETHERNET &&
	    (cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_WIFI &&
	    (cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_TOKEN_RING))
		return 0; /* Not our kind of file */

	/* No file header. Reset the fh to 0 so we can read the first packet */
	if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
		return -1;

	/* Set up the pointers to the handlers for this file type */
	wth->subtype_read = commview_read;
	wth->subtype_seek_read = commview_seek_read;

	wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COMMVIEW;
	wth->file_encap = WTAP_ENCAP_PER_PACKET;
	wth->tsprecision = WTAP_FILE_TSPREC_USEC;

	return 1; /* Our kind of file */
}
Beispiel #3
0
static gboolean
commview_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header
		   *pseudo_header, guint8 *pd, int length, int *err,
		   gchar **err_info)
{
	commview_header_t cv_hdr;
	int bytes_read;

	if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
		return FALSE;

	if(!commview_read_header(&cv_hdr, wth->random_fh, err, err_info)) {
		if(*err == 0)
			*err = WTAP_ERR_SHORT_READ;

		return FALSE;
	}

	if(length != cv_hdr.data_len) {
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("commview: record length %u doesn't match requested length %d", cv_hdr.data_len, length);
		return FALSE;
	}

	commview_set_pseudo_header(&cv_hdr, pseudo_header);

	bytes_read = file_read(pd, cv_hdr.data_len, wth->random_fh);
	if(bytes_read != cv_hdr.data_len) {
		*err = file_error(wth->random_fh, err_info);
		if(*err == 0)
			*err = WTAP_ERR_SHORT_READ;

		return FALSE;
	}

	return TRUE;
}
Beispiel #4
0
static gboolean
commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
	commview_header_t cv_hdr;
	struct tm tm;
	int bytes_read;

	*data_offset = wth->data_offset;

	if(!commview_read_header(&cv_hdr, wth->fh, err, err_info))
		return FALSE;

	wth->data_offset += COMMVIEW_HEADER_SIZE;

	switch(cv_hdr.flags & FLAGS_MEDIUM) {

	case MEDIUM_ETHERNET :
		wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET;
		break;

	case MEDIUM_WIFI :
		wth->phdr.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
		break;

	case MEDIUM_TOKEN_RING :
		wth->phdr.pkt_encap = WTAP_ENCAP_TOKEN_RING;
		break;

	default :
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("commview: unsupported encap: %u",
					    cv_hdr.flags & FLAGS_MEDIUM);
		return FALSE;
	}

	commview_set_pseudo_header(&cv_hdr, &wth->pseudo_header);

	buffer_assure_space(wth->frame_buffer, cv_hdr.data_len);
	bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
			       cv_hdr.data_len, wth->fh);
	if(bytes_read != cv_hdr.data_len) {
		*err = file_error(wth->fh, err_info);
		if(*err == 0)
			*err = WTAP_ERR_SHORT_READ;
		return FALSE;
	}

	tm.tm_year = cv_hdr.year - 1900;
	tm.tm_mon = cv_hdr.month - 1;
	tm.tm_mday = cv_hdr.day;
	tm.tm_hour = cv_hdr.hours;
	tm.tm_min = cv_hdr.minutes;
	tm.tm_sec = cv_hdr.seconds;
	tm.tm_isdst = -1;

	wth->data_offset += cv_hdr.data_len;

	wth->phdr.presence_flags = WTAP_HAS_TS;

	wth->phdr.len = cv_hdr.data_len;
	wth->phdr.caplen = cv_hdr.data_len;

	wth->phdr.ts.secs = mktime(&tm);
	wth->phdr.ts.nsecs = cv_hdr.usecs * 1000;

	return TRUE;
}
Beispiel #5
0
static int
commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
    int *err, gchar **err_info)
{
	commview_header_t cv_hdr;
	struct tm tm;
	guint frequency;

	if(!commview_read_header(&cv_hdr, fh, err, err_info))
		return FALSE;

	switch(cv_hdr.flags & FLAGS_MEDIUM) {

	case MEDIUM_ETHERNET :
		phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
		phdr->pseudo_header.eth.fcs_len = -1; /* Unknown */
		break;

	case MEDIUM_WIFI :
		phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
		phdr->pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */
		phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
		phdr->pseudo_header.ieee_802_11.datapad = FALSE;
		phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN;
		phdr->pseudo_header.ieee_802_11.presence_flags =
		    PHDR_802_11_HAS_CHANNEL |
		    PHDR_802_11_HAS_DATA_RATE |
		    PHDR_802_11_HAS_SIGNAL_PERCENT;
		switch (cv_hdr.band) {

		case BAND_11A:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11a.presence_flags =
			    PHDR_802_11A_HAS_TURBO_TYPE;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
			    PHDR_802_11A_TURBO_TYPE_NORMAL;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
			break;

		case BAND_11B:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11B;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11b.presence_flags = 0;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
			break;

		case BAND_11G:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11g.presence_flags =
			    PHDR_802_11G_HAS_MODE;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode =
			    PHDR_802_11G_MODE_NORMAL;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
			break;

		case BAND_11A_TURBO:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11A;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11a.presence_flags =
			    PHDR_802_11A_HAS_TURBO_TYPE;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11a.turbo_type =
			    PHDR_802_11A_TURBO_TYPE_TURBO;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
			break;

		case BAND_SUPERG:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11G;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11g.presence_flags =
			    PHDR_802_11G_HAS_MODE;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11g.mode =
			    PHDR_802_11G_MODE_SUPER_G;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
			break;

		case BAND_11N_5GHZ:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11n.presence_flags =
			    0;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, FALSE);
			break;

		case BAND_11N_2_4GHZ:
			phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_11N;
			phdr->pseudo_header.ieee_802_11.phy_info.info_11n.presence_flags =
			    0;
			frequency = ieee80211_chan_to_mhz(cv_hdr.channel, TRUE);
			break;

		case BAND_PUBLIC_SAFETY:
			/*
			 * XXX - what do we do here?  What are the channel
			 * numbers?  How do we distinguish the several
			 * different flavors of 4.9 GHz frequencies?
			 */
			frequency = 0;
			break;

		default:
			frequency = 0;
			break;
		}
		if (frequency != 0) {
			phdr->pseudo_header.ieee_802_11.presence_flags |=
			    PHDR_802_11_HAS_FREQUENCY;
			phdr->pseudo_header.ieee_802_11.frequency = frequency;
		}
		phdr->pseudo_header.ieee_802_11.channel = cv_hdr.channel;
		phdr->pseudo_header.ieee_802_11.data_rate =
		    cv_hdr.rate | (cv_hdr.direction << 8);
		phdr->pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent;

		/*
		 * XXX - these are positive in captures I've seen; does
		 * that mean that they are the negative of the actual
		 * dBm value?  (80 dBm is a bit more power than most
		 * countries' regulatory agencies are likely to allow
		 * any individual to have in their home. :-))
		 *
		 * XXX - sometimes these are 0; assume that means that no
		 * value is provided.
		 */
		if (cv_hdr.signal_level_dbm != 0) {
			phdr->pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm;
			phdr->pseudo_header.ieee_802_11.presence_flags |=
			    PHDR_802_11_HAS_SIGNAL_DBM;
		}
		if (cv_hdr.noise_level != 0) {
			phdr->pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level;
			phdr->pseudo_header.ieee_802_11.presence_flags |=
			    PHDR_802_11_HAS_NOISE_DBM;
		}
		break;

	case MEDIUM_TOKEN_RING :
		phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
		break;

	default :
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("commview: unsupported encap: %u",
					    cv_hdr.flags & FLAGS_MEDIUM);
		return FALSE;
	}

	tm.tm_year = cv_hdr.year - 1900;
	tm.tm_mon = cv_hdr.month - 1;
	tm.tm_mday = cv_hdr.day;
	tm.tm_hour = cv_hdr.hours;
	tm.tm_min = cv_hdr.minutes;
	tm.tm_sec = cv_hdr.seconds;
	tm.tm_isdst = -1;

	phdr->rec_type = REC_TYPE_PACKET;
	phdr->presence_flags = WTAP_HAS_TS;

	phdr->len = cv_hdr.data_len;
	phdr->caplen = cv_hdr.data_len;

	phdr->ts.secs = mktime(&tm);
	phdr->ts.nsecs = cv_hdr.usecs * 1000;

	return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}