예제 #1
0
void
ieee80211_dump_pkt(struct ieee80211com *ic,
	const u_int8_t *buf, int len, int rate, int rssi)
{
	const struct ieee80211_frame *wh;
	int i;

	wh = (const struct ieee80211_frame *)buf;
	switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
	case IEEE80211_FC1_DIR_NODS:
		printf("NODS %s", ether_sprintf(wh->i_addr2));
		printf("->%s", ether_sprintf(wh->i_addr1));
		printf("(%s)", ether_sprintf(wh->i_addr3));
		break;
	case IEEE80211_FC1_DIR_TODS:
		printf("TODS %s", ether_sprintf(wh->i_addr2));
		printf("->%s", ether_sprintf(wh->i_addr3));
		printf("(%s)", ether_sprintf(wh->i_addr1));
		break;
	case IEEE80211_FC1_DIR_FROMDS:
		printf("FRDS %s", ether_sprintf(wh->i_addr3));
		printf("->%s", ether_sprintf(wh->i_addr1));
		printf("(%s)", ether_sprintf(wh->i_addr2));
		break;
	case IEEE80211_FC1_DIR_DSTODS:
		printf("DSDS %s", ether_sprintf((u_int8_t *)&wh[1]));
		printf("->%s", ether_sprintf(wh->i_addr3));
		printf("(%s", ether_sprintf(wh->i_addr2));
		printf("->%s)", ether_sprintf(wh->i_addr1));
		break;
	}
	switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
	case IEEE80211_FC0_TYPE_DATA:
		printf(" data");
		break;
	case IEEE80211_FC0_TYPE_MGT:
		printf(" %s", ieee80211_mgt_subtype_name[
			(wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK)
			>> IEEE80211_FC0_SUBTYPE_SHIFT]);
		break;
	default:
		printf(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
		break;
	}
	if (IEEE80211_QOS_HAS_SEQ(wh)) {
		const struct ieee80211_qosframe *qwh = 
			(const struct ieee80211_qosframe *)buf;
		printf(" QoS [TID %u%s]", qwh->i_qos[0] & IEEE80211_QOS_TID,
			qwh->i_qos[0] & IEEE80211_QOS_ACKPOLICY ? " ACM" : "");
	}
	if (wh->i_fc[1] & IEEE80211_FC1_PROT) {
		int off;

		off = ieee80211_anyhdrspace(ic, wh);
		printf(" WEP [IV %.02x %.02x %.02x",
			buf[off+0], buf[off+1], buf[off+2]);
		if (buf[off+IEEE80211_WEP_IVLEN] & IEEE80211_WEP_EXTIV)
			printf(" %.02x %.02x %.02x",
				buf[off+4], buf[off+5], buf[off+6]);
		printf(" KID %u]", buf[off+IEEE80211_WEP_IVLEN] >> 6);
	}
예제 #2
0
static int ieee80211_crypto_keymiss(struct ieee80211_node *ni, wbuf_t wbuf, struct ieee80211_rx_status *rs)
{
    struct ieee80211vap *vap = ni->ni_vap;
    struct ieee80211com *ic = vap->iv_ic;
    struct ieee80211_frame *wh;
    int off, kid, hdrspace;
    u_int8_t *buf = NULL;
    struct ieee80211_key k, *key = NULL; 
    const struct ieee80211_cipher *cip;
    struct ieee80211_node_table *nt = &ic->ic_sta;
    struct ieee80211_node *sender=NULL;

    /* 
     * Verify if WEP is set and
     * retrieve the key index from the packet.
     */
    wh = (struct ieee80211_frame *)wbuf_header(wbuf);
    buf = (u_int8_t*)wbuf_raw_data(wbuf);

    if (wh->i_fc[1] & IEEE80211_FC1_WEP) {

        off = ieee80211_anyhdrspace(ic, wh);
        kid = buf[off+IEEE80211_WEP_IVLEN] >> 6;

        sender = ieee80211_find_node(nt, wh->i_addr2);
        if(sender == NULL) {
            IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "%s: Node not found\n",
                                                __func__);
            goto bad; 
        }

        /* 
         * Using the key index specified in the packet.
         */
        if (kid >= IEEE80211_WEP_NKID) {
	    IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "%s: Incorrect keyid (%d) specified in the packet!\n",
                                             __func__, kid);
            goto bad;
        }
        key = &vap->iv_nw_keys[kid];
        cip = key->wk_cipher;
        if (cip->ic_cipher != IEEE80211_CIPHER_WEP) {
            ieee80211_free_node(sender);
            return 1;
        }
        hdrspace = ieee80211_hdrspace(ic, wh);

        IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "%s: kid=%d, ni=0x%p, sender=0x%p, vap=0x%p\n",
                                             __func__, kid, ni, sender, vap);
        /*
         * Create a temporary key for installing the
         * rx key for the station.
         */
        OS_MEMCPY(&k, key, sizeof(*key));
        k.wk_flags |= IEEE80211_KEY_SWCRYPT;

        if (cip->ic_decap(&k, wbuf, hdrspace, rs) ) {
            IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "Decrypt using entry(s) %d worked.\n",
                                                 key->wk_keyix);
            wh = (struct ieee80211_frame *)wbuf_header(wbuf);
            /*
             * The packet has been decrypted correctly, therefore the WEP bit 
             * should be cleared.
             */
            wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
            k.wk_flags &= ~IEEE80211_KEY_SWCRYPT;

            if (!crypto_installkey(&k, vap, sender))
                goto bad; 
            sender->ni_wep_mbssid.rxvapkey = key;
	    
            if(vap->iv_opmode == IEEE80211_M_STA) {
                if (!crypto_install_mcastkey(&k, vap, sender))
                    goto bad;
            }
            ieee80211_free_node(sender);
            key->wk_private = k.wk_private;
            return 1;
        } else 
            IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO, "Decrypt using entry(s) %d didn't work.\n", 
                                                  key->wk_keyix);
    } /* if wep is enabled */