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