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