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