1e5b75505Sopenharmony_ci/*
2e5b75505Sopenharmony_ci * hostapd / P2P integration
3e5b75505Sopenharmony_ci * Copyright (c) 2009-2010, Atheros Communications
4e5b75505Sopenharmony_ci *
5e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license.
6e5b75505Sopenharmony_ci * See README for more details.
7e5b75505Sopenharmony_ci */
8e5b75505Sopenharmony_ci
9e5b75505Sopenharmony_ci#include "utils/includes.h"
10e5b75505Sopenharmony_ci
11e5b75505Sopenharmony_ci#include "utils/common.h"
12e5b75505Sopenharmony_ci#include "common/ieee802_11_defs.h"
13e5b75505Sopenharmony_ci#include "p2p/p2p.h"
14e5b75505Sopenharmony_ci#include "hostapd.h"
15e5b75505Sopenharmony_ci#include "ap_config.h"
16e5b75505Sopenharmony_ci#include "ap_drv_ops.h"
17e5b75505Sopenharmony_ci#include "sta_info.h"
18e5b75505Sopenharmony_ci#include "p2p_hostapd.h"
19e5b75505Sopenharmony_ci
20e5b75505Sopenharmony_ci
21e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
22e5b75505Sopenharmony_ci
23e5b75505Sopenharmony_ciint hostapd_p2p_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
24e5b75505Sopenharmony_ci			    char *buf, size_t buflen)
25e5b75505Sopenharmony_ci{
26e5b75505Sopenharmony_ci	if (sta->p2p_ie == NULL)
27e5b75505Sopenharmony_ci		return 0;
28e5b75505Sopenharmony_ci
29e5b75505Sopenharmony_ci	return p2p_ie_text(sta->p2p_ie, buf, buf + buflen);
30e5b75505Sopenharmony_ci}
31e5b75505Sopenharmony_ci
32e5b75505Sopenharmony_ci
33e5b75505Sopenharmony_ciint hostapd_p2p_set_noa(struct hostapd_data *hapd, u8 count, int start,
34e5b75505Sopenharmony_ci			int duration)
35e5b75505Sopenharmony_ci{
36e5b75505Sopenharmony_ci	wpa_printf(MSG_DEBUG, "P2P: Set NoA parameters: count=%u start=%d "
37e5b75505Sopenharmony_ci		   "duration=%d", count, start, duration);
38e5b75505Sopenharmony_ci
39e5b75505Sopenharmony_ci	if (count == 0) {
40e5b75505Sopenharmony_ci		hapd->noa_enabled = 0;
41e5b75505Sopenharmony_ci		hapd->noa_start = 0;
42e5b75505Sopenharmony_ci		hapd->noa_duration = 0;
43e5b75505Sopenharmony_ci	}
44e5b75505Sopenharmony_ci
45e5b75505Sopenharmony_ci	if (count != 255) {
46e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "P2P: Non-periodic NoA - set "
47e5b75505Sopenharmony_ci			   "NoA parameters");
48e5b75505Sopenharmony_ci		return hostapd_driver_set_noa(hapd, count, start, duration);
49e5b75505Sopenharmony_ci	}
50e5b75505Sopenharmony_ci
51e5b75505Sopenharmony_ci	hapd->noa_enabled = 1;
52e5b75505Sopenharmony_ci	hapd->noa_start = start;
53e5b75505Sopenharmony_ci	hapd->noa_duration = duration;
54e5b75505Sopenharmony_ci
55e5b75505Sopenharmony_ci	if (hapd->num_sta_no_p2p == 0) {
56e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "P2P: No legacy STAs connected - update "
57e5b75505Sopenharmony_ci			   "periodic NoA parameters");
58e5b75505Sopenharmony_ci		return hostapd_driver_set_noa(hapd, count, start, duration);
59e5b75505Sopenharmony_ci	}
60e5b75505Sopenharmony_ci
61e5b75505Sopenharmony_ci	wpa_printf(MSG_DEBUG, "P2P: Legacy STA(s) connected - do not enable "
62e5b75505Sopenharmony_ci		   "periodic NoA");
63e5b75505Sopenharmony_ci
64e5b75505Sopenharmony_ci	return 0;
65e5b75505Sopenharmony_ci}
66e5b75505Sopenharmony_ci
67e5b75505Sopenharmony_ci
68e5b75505Sopenharmony_civoid hostapd_p2p_non_p2p_sta_connected(struct hostapd_data *hapd)
69e5b75505Sopenharmony_ci{
70e5b75505Sopenharmony_ci	wpa_printf(MSG_DEBUG, "P2P: First non-P2P device connected");
71e5b75505Sopenharmony_ci
72e5b75505Sopenharmony_ci	if (hapd->noa_enabled) {
73e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "P2P: Disable periodic NoA");
74e5b75505Sopenharmony_ci		hostapd_driver_set_noa(hapd, 0, 0, 0);
75e5b75505Sopenharmony_ci	}
76e5b75505Sopenharmony_ci}
77e5b75505Sopenharmony_ci
78e5b75505Sopenharmony_ci
79e5b75505Sopenharmony_civoid hostapd_p2p_non_p2p_sta_disconnected(struct hostapd_data *hapd)
80e5b75505Sopenharmony_ci{
81e5b75505Sopenharmony_ci	wpa_printf(MSG_DEBUG, "P2P: Last non-P2P device disconnected");
82e5b75505Sopenharmony_ci
83e5b75505Sopenharmony_ci	if (hapd->noa_enabled) {
84e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "P2P: Enable periodic NoA");
85e5b75505Sopenharmony_ci		hostapd_driver_set_noa(hapd, 255, hapd->noa_start,
86e5b75505Sopenharmony_ci				       hapd->noa_duration);
87e5b75505Sopenharmony_ci	}
88e5b75505Sopenharmony_ci}
89e5b75505Sopenharmony_ci
90e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
91e5b75505Sopenharmony_ci
92e5b75505Sopenharmony_ci
93e5b75505Sopenharmony_ci#ifdef CONFIG_P2P_MANAGER
94e5b75505Sopenharmony_ciu8 * hostapd_eid_p2p_manage(struct hostapd_data *hapd, u8 *eid)
95e5b75505Sopenharmony_ci{
96e5b75505Sopenharmony_ci	u8 bitmap;
97e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_VENDOR_SPECIFIC;
98e5b75505Sopenharmony_ci	*eid++ = 4 + 3 + 1;
99e5b75505Sopenharmony_ci	WPA_PUT_BE32(eid, P2P_IE_VENDOR_TYPE);
100e5b75505Sopenharmony_ci	eid += 4;
101e5b75505Sopenharmony_ci
102e5b75505Sopenharmony_ci	*eid++ = P2P_ATTR_MANAGEABILITY;
103e5b75505Sopenharmony_ci	WPA_PUT_LE16(eid, 1);
104e5b75505Sopenharmony_ci	eid += 2;
105e5b75505Sopenharmony_ci	bitmap = P2P_MAN_DEVICE_MANAGEMENT;
106e5b75505Sopenharmony_ci	if (hapd->conf->p2p & P2P_ALLOW_CROSS_CONNECTION)
107e5b75505Sopenharmony_ci		bitmap |= P2P_MAN_CROSS_CONNECTION_PERMITTED;
108e5b75505Sopenharmony_ci	bitmap |= P2P_MAN_COEXISTENCE_OPTIONAL;
109e5b75505Sopenharmony_ci	*eid++ = bitmap;
110e5b75505Sopenharmony_ci
111e5b75505Sopenharmony_ci	return eid;
112e5b75505Sopenharmony_ci}
113e5b75505Sopenharmony_ci#endif /* CONFIG_P2P_MANAGER */
114