예제 #1
0
파일: pcap.c 프로젝트: jolin90/smartconfig
static int print_radiotap_field(struct smartconfig *sc, struct cpack_state *s,
								uint32_t bit, uint8_t * flagsp, uint32_t presentflags, uint16_t * channel)
{
	int rc;

	switch (bit) {

	case IEEE80211_RADIOTAP_TSFT:{
			uint64_t tsft;

			rc = cpack_uint64(s, &tsft);
			if (rc != 0)
				goto trunc;
			break;
		}

	case IEEE80211_RADIOTAP_FLAGS:{
			uint8_t flagsval;

			rc = cpack_uint8(s, &flagsval);
			if (rc != 0)
				goto trunc;
			*flagsp = flagsval;
			break;
		}

	case IEEE80211_RADIOTAP_RATE:{
			uint8_t rate;

			rc = cpack_uint8(s, &rate);
			if (rc != 0)
				goto trunc;
			break;
		}

	case IEEE80211_RADIOTAP_CHANNEL:{
			uint16_t frequency;
			uint16_t flags;

			rc = cpack_uint16(s, &frequency);
			if (rc != 0)
				goto trunc;
			rc = cpack_uint16(s, &flags);
			if (rc != 0)
				goto trunc;
			*channel = frequency;
			break;
		}

	default:
		return -1;
	}

	return 0;

trunc:
	return rc;
}
예제 #2
0
static int
print_radiotap_field(struct cpack_state *s, u_int32_t bit, int *pad)
{
	union {
		int8_t		i8;
		u_int8_t	u8;
		int16_t		i16;
		u_int16_t	u16;
		u_int32_t	u32;
		u_int64_t	u64;
	} u, u2;
	int rc;

	switch (bit) {
	case IEEE80211_RADIOTAP_FLAGS:
		rc = cpack_uint8(s, &u.u8);
		if (u.u8 & IEEE80211_RADIOTAP_F_DATAPAD)
			*pad = 1;
		break;
	case IEEE80211_RADIOTAP_RATE:
	case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
	case IEEE80211_RADIOTAP_DB_ANTNOISE:
	case IEEE80211_RADIOTAP_ANTENNA:
		rc = cpack_uint8(s, &u.u8);
		break;
	case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
	case IEEE80211_RADIOTAP_DBM_ANTNOISE:
		rc = cpack_int8(s, &u.i8);
		break;
	case IEEE80211_RADIOTAP_CHANNEL:
		rc = cpack_uint16(s, &u.u16);
		if (rc != 0)
			break;
		rc = cpack_uint16(s, &u2.u16);
		break;
	case IEEE80211_RADIOTAP_FHSS:
	case IEEE80211_RADIOTAP_LOCK_QUALITY:
	case IEEE80211_RADIOTAP_TX_ATTENUATION:
		rc = cpack_uint16(s, &u.u16);
		break;
	case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
		rc = cpack_uint8(s, &u.u8);
		break;
	case IEEE80211_RADIOTAP_DBM_TX_POWER:
		rc = cpack_int8(s, &u.i8);
		break;
	case IEEE80211_RADIOTAP_TSFT:
		rc = cpack_uint64(s, &u.u64);
		break;
	default:
		/* this bit indicates a field whose
		 * size we do not know, so we cannot
		 * proceed.
		 */
		printf("[0x%08x] ", bit);
		return -1;
	}

	if (rc != 0) {
		printf("[|802.11]");
		return rc;
	}

	switch (bit) {
	case IEEE80211_RADIOTAP_CHANNEL:
		printf("%u MHz ", u.u16);
		if (u2.u16 != 0)
			printf("(0x%04x) ", u2.u16);
		break;
	case IEEE80211_RADIOTAP_FHSS:
		printf("fhset %d fhpat %d ", u.u16 & 0xff, (u.u16 >> 8) & 0xff);
		break;
	case IEEE80211_RADIOTAP_RATE:
		PRINT_RATE("", u.u8, " Mb/s ");
		break;
	case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
		printf("%ddB signal ", u.i8);
		break;
	case IEEE80211_RADIOTAP_DBM_ANTNOISE:
		printf("%ddB noise ", u.i8);
		break;
	case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
		printf("%ddB signal ", u.u8);
		break;
	case IEEE80211_RADIOTAP_DB_ANTNOISE:
		printf("%ddB noise ", u.u8);
		break;
	case IEEE80211_RADIOTAP_LOCK_QUALITY:
		printf("%u sq ", u.u16);
		break;
	case IEEE80211_RADIOTAP_TX_ATTENUATION:
		printf("%d tx power ", -(int)u.u16);
		break;
	case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
		printf("%ddB tx power ", -(int)u.u8);
		break;
	case IEEE80211_RADIOTAP_DBM_TX_POWER:
		printf("%ddBm tx power ", u.i8);
		break;
	case IEEE80211_RADIOTAP_FLAGS:
		if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
			printf("cfp ");
		if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
			printf("short preamble ");
		if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
			printf("wep ");
		if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
			printf("fragmented ");
		if (u.u8 & IEEE80211_RADIOTAP_F_BADFCS)
			printf("bad-fcs ");
		break;
	case IEEE80211_RADIOTAP_ANTENNA:
		printf("antenna %d ", u.u8);
		break;
	case IEEE80211_RADIOTAP_TSFT:
		printf("%" PRIu64 "us tsft ", u.u64);
		break;
	}
	return 0;
}