LCOV - code coverage report
Current view: top level - src/ap - p2p_hostapd.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 26 47 55.3 %
Date: 2015-09-27 Functions: 4 5 80.0 %

          Line data    Source code
       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           4 : int hostapd_p2p_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
      24             :                             char *buf, size_t buflen)
      25             : {
      26           4 :         if (sta->p2p_ie == NULL)
      27           3 :                 return 0;
      28             : 
      29           1 :         return p2p_ie_text(sta->p2p_ie, buf, buf + buflen);
      30             : }
      31             : 
      32             : 
      33           0 : int hostapd_p2p_set_noa(struct hostapd_data *hapd, u8 count, int start,
      34             :                         int duration)
      35             : {
      36           0 :         wpa_printf(MSG_DEBUG, "P2P: Set NoA parameters: count=%u start=%d "
      37             :                    "duration=%d", count, start, duration);
      38             : 
      39           0 :         if (count == 0) {
      40           0 :                 hapd->noa_enabled = 0;
      41           0 :                 hapd->noa_start = 0;
      42           0 :                 hapd->noa_duration = 0;
      43             :         }
      44             : 
      45           0 :         if (count != 255) {
      46           0 :                 wpa_printf(MSG_DEBUG, "P2P: Non-periodic NoA - set "
      47             :                            "NoA parameters");
      48           0 :                 return hostapd_driver_set_noa(hapd, count, start, duration);
      49             :         }
      50             : 
      51           0 :         hapd->noa_enabled = 1;
      52           0 :         hapd->noa_start = start;
      53           0 :         hapd->noa_duration = duration;
      54             : 
      55           0 :         if (hapd->num_sta_no_p2p == 0) {
      56           0 :                 wpa_printf(MSG_DEBUG, "P2P: No legacy STAs connected - update "
      57             :                            "periodic NoA parameters");
      58           0 :                 return hostapd_driver_set_noa(hapd, count, start, duration);
      59             :         }
      60             : 
      61           0 :         wpa_printf(MSG_DEBUG, "P2P: Legacy STA(s) connected - do not enable "
      62             :                    "periodic NoA");
      63             : 
      64           0 :         return 0;
      65             : }
      66             : 
      67             : 
      68          36 : void hostapd_p2p_non_p2p_sta_connected(struct hostapd_data *hapd)
      69             : {
      70          36 :         wpa_printf(MSG_DEBUG, "P2P: First non-P2P device connected");
      71             : 
      72          36 :         if (hapd->noa_enabled) {
      73           0 :                 wpa_printf(MSG_DEBUG, "P2P: Disable periodic NoA");
      74           0 :                 hostapd_driver_set_noa(hapd, 0, 0, 0);
      75             :         }
      76          36 : }
      77             : 
      78             : 
      79          36 : void hostapd_p2p_non_p2p_sta_disconnected(struct hostapd_data *hapd)
      80             : {
      81          36 :         wpa_printf(MSG_DEBUG, "P2P: Last non-P2P device disconnected");
      82             : 
      83          36 :         if (hapd->noa_enabled) {
      84           0 :                 wpa_printf(MSG_DEBUG, "P2P: Enable periodic NoA");
      85           0 :                 hostapd_driver_set_noa(hapd, 255, hapd->noa_start,
      86             :                                        hapd->noa_duration);
      87             :         }
      88          36 : }
      89             : 
      90             : #endif /* CONFIG_P2P */
      91             : 
      92             : 
      93             : #ifdef CONFIG_P2P_MANAGER
      94          31 : u8 * hostapd_eid_p2p_manage(struct hostapd_data *hapd, u8 *eid)
      95             : {
      96             :         u8 bitmap;
      97          31 :         *eid++ = WLAN_EID_VENDOR_SPECIFIC;
      98          31 :         *eid++ = 4 + 3 + 1;
      99          31 :         WPA_PUT_BE32(eid, P2P_IE_VENDOR_TYPE);
     100          31 :         eid += 4;
     101             : 
     102          31 :         *eid++ = P2P_ATTR_MANAGEABILITY;
     103          31 :         WPA_PUT_LE16(eid, 1);
     104          31 :         eid += 2;
     105          31 :         bitmap = P2P_MAN_DEVICE_MANAGEMENT;
     106          31 :         if (hapd->conf->p2p & P2P_ALLOW_CROSS_CONNECTION)
     107           6 :                 bitmap |= P2P_MAN_CROSS_CONNECTION_PERMITTED;
     108          31 :         bitmap |= P2P_MAN_COEXISTENCE_OPTIONAL;
     109          31 :         *eid++ = bitmap;
     110             : 
     111          31 :         return eid;
     112             : }
     113             : #endif /* CONFIG_P2P_MANAGER */

Generated by: LCOV version 1.10