static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
				       const u8 *addr, const u8 *frm, int len)
{
	/* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
	const u8 *pos = frm;
	u8 dialog_token;
	struct wnm_sleep_element *wnmsleep_ie = NULL;
	/* multiple TFS Req IE (assuming consecutive) */
	u8 *tfsreq_ie_start = NULL;
	u8 *tfsreq_ie_end = NULL;
	u16 tfsreq_ie_len = 0;

	dialog_token = *pos++;
	while (pos + 1 < frm + len) {
		u8 ie_len = pos[1];
		if (pos + 2 + ie_len > frm + len)
			break;
		if (*pos == WLAN_EID_WNMSLEEP)
			wnmsleep_ie = (struct wnm_sleep_element *) pos;
		else if (*pos == WLAN_EID_TFS_REQ) {
			if (!tfsreq_ie_start)
				tfsreq_ie_start = (u8 *) pos;
			tfsreq_ie_end = (u8 *) pos;
		} else
			wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
				   *pos);
		pos += ie_len + 2;
	}

	if (!wnmsleep_ie) {
		wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
		return;
	}

	if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
	    tfsreq_ie_start && tfsreq_ie_end &&
	    tfsreq_ie_end - tfsreq_ie_start >= 0) {
		tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
			tfsreq_ie_start;
		wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
		/* pass the TFS Req IE(s) to driver for processing */
		if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
					    &tfsreq_ie_len,
					    WNM_SLEEP_TFS_REQ_IE_SET))
			wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
	}

	ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
				      wnmsleep_ie->action_type,
				      le_to_host16(wnmsleep_ie->intval));

	if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
		/* clear the tfs after sending the resp frame */
		ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
					&tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
	}
}
Beispiel #2
0
static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s,
					 const u8 *tfsresp_ie_start,
					 const u8 *tfsresp_ie_end)
{
	wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM,
			 wpa_s->bssid, NULL, NULL);
	/* remove GTK/IGTK ?? */

	/* set the TFS Resp IE(s) */
	if (tfsresp_ie_start && tfsresp_ie_end &&
	    tfsresp_ie_end - tfsresp_ie_start >= 0) {
		u16 tfsresp_ie_len;
		tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) -
			tfsresp_ie_start;
		wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found");
		/* pass the TFS Resp IE(s) to driver for processing */
		if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid,
					    tfsresp_ie_start,
					    tfsresp_ie_len,
					    WNM_SLEEP_TFS_RESP_IE_SET))
			wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE");
	}
}
static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s,
					const u8 *frm, int len)
{
	/*
	 * Action [1] | Diaglog Token [1] | Key Data Len [2] | Key Data |
	 * WNM-Sleep Mode IE | TFS Response IE
	 */
	u8 *pos = (u8 *) frm; /* point to action field */
	u16 key_len_total = le_to_host16(*((u16 *)(frm+2)));
	u8 gtk_len;
#ifdef CONFIG_IEEE80211W
	u8 igtk_len;
#endif /* CONFIG_IEEE80211W */
	struct wnm_sleep_element *wnmsleep_ie = NULL;
	/* multiple TFS Resp IE (assuming consecutive) */
	u8 *tfsresp_ie_start = NULL;
	u8 *tfsresp_ie_end = NULL;
	u16 tfsresp_ie_len = 0;

	wpa_printf(MSG_DEBUG, "action=%d token = %d key_len_total = %d",
		   frm[0], frm[1], key_len_total);
	pos += 4 + key_len_total;
	while (pos - frm < len) {
		u8 ie_len = *(pos + 1);
		if (*pos == WLAN_EID_WNMSLEEP)
			wnmsleep_ie = (struct wnm_sleep_element *) pos;
		else if (*pos == WLAN_EID_TFS_RESP) {
			if (!tfsresp_ie_start)
				tfsresp_ie_start = pos;
			tfsresp_ie_end = pos;
		} else
			wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos);
		pos += ie_len + 2;
	}

	if (!wnmsleep_ie) {
		wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
		return;
	}

	if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT) {
		wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response "
			   "frame (action=%d, intval=%d)",
			   wnmsleep_ie->action_type, wnmsleep_ie->intval);
		if (wnmsleep_ie->action_type == 0) {
			wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM,
					 wpa_s->bssid, NULL, NULL);
			/* remove GTK/IGTK ?? */

			/* set the TFS Resp IE(s) */
			if (tfsresp_ie_start && tfsresp_ie_end &&
			    tfsresp_ie_end - tfsresp_ie_start >= 0) {
				tfsresp_ie_len = (tfsresp_ie_end +
						  tfsresp_ie_end[1] + 2) -
					tfsresp_ie_start;
				wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found");
				/*
				 * pass the TFS Resp IE(s) to driver for
				 * processing
				 */
				if (ieee80211_11_set_tfs_ie(
					    wpa_s, wpa_s->bssid,
					    tfsresp_ie_start,
					    &tfsresp_ie_len,
					    WNM_SLEEP_TFS_RESP_IE_SET))
					wpa_printf(MSG_DEBUG, "Fail to set "
						   "TFS Resp IE");
			}
		} else if (wnmsleep_ie->action_type == 1) {
			wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM,
					 wpa_s->bssid, NULL, NULL);
			/* Install GTK/IGTK */
			do {
				/* point to key data field */
				u8 *ptr = (u8 *) frm + 1 + 1 + 2;
				while (ptr < (u8 *) frm + 4 + key_len_total) {
					if (*ptr == WNM_SLEEP_SUBELEM_GTK) {
						gtk_len = *(ptr + 4);
						wpa_wnmsleep_install_key(
							wpa_s->wpa,
							WNM_SLEEP_SUBELEM_GTK,
							ptr);
						ptr += 13 + gtk_len;
#ifdef CONFIG_IEEE80211W
					} else if (*ptr ==
						   WNM_SLEEP_SUBELEM_IGTK) {
						igtk_len = WPA_IGTK_LEN;
						wpa_wnmsleep_install_key(
							wpa_s->wpa,
							WNM_SLEEP_SUBELEM_IGTK,
							ptr);
						ptr += 10 + WPA_IGTK_LEN;
#endif /* CONFIG_IEEE80211W */
					} else
						break; /* skip the loop */
				}
			} while(0);
		}
	} else {
		wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame "
			   "(action=%d, intval=%d)",
			   wnmsleep_ie->action_type, wnmsleep_ie->intval);
		if (wnmsleep_ie->action_type == 0)
			wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL,
					 wpa_s->bssid, NULL, NULL);
		else if (wnmsleep_ie->action_type == 1)
			wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL,
					 wpa_s->bssid, NULL, NULL);
	}
}