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 1393793999 Lines: 27 48 56.2 %
Date: 2014-03-02 Functions: 4 5 80.0 %
Branches: 5 14 35.7 %

           Branch data     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                 :          3 : int hostapd_p2p_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
      24                 :            :                             char *buf, size_t buflen)
      25                 :            : {
      26         [ +  - ]:          3 :         if (sta->p2p_ie == NULL)
      27                 :          3 :                 return 0;
      28                 :            : 
      29                 :          3 :         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                 :         16 : void hostapd_p2p_non_p2p_sta_connected(struct hostapd_data *hapd)
      69                 :            : {
      70                 :         16 :         wpa_printf(MSG_DEBUG, "P2P: First non-P2P device connected");
      71                 :            : 
      72         [ -  + ]:         16 :         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                 :         16 : }
      77                 :            : 
      78                 :            : 
      79                 :         16 : void hostapd_p2p_non_p2p_sta_disconnected(struct hostapd_data *hapd)
      80                 :            : {
      81                 :         16 :         wpa_printf(MSG_DEBUG, "P2P: Last non-P2P device disconnected");
      82                 :            : 
      83         [ -  + ]:         16 :         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                 :         16 : }
      89                 :            : 
      90                 :            : #endif /* CONFIG_P2P */
      91                 :            : 
      92                 :            : 
      93                 :            : #ifdef CONFIG_P2P_MANAGER
      94                 :         12 : u8 * hostapd_eid_p2p_manage(struct hostapd_data *hapd, u8 *eid)
      95                 :            : {
      96                 :            :         u8 bitmap;
      97                 :         12 :         *eid++ = WLAN_EID_VENDOR_SPECIFIC;
      98                 :         12 :         *eid++ = 4 + 3 + 1;
      99                 :         12 :         WPA_PUT_BE24(eid, OUI_WFA);
     100                 :         12 :         eid += 3;
     101                 :         12 :         *eid++ = P2P_OUI_TYPE;
     102                 :            : 
     103                 :         12 :         *eid++ = P2P_ATTR_MANAGEABILITY;
     104                 :         12 :         WPA_PUT_LE16(eid, 1);
     105                 :         12 :         eid += 2;
     106                 :         12 :         bitmap = P2P_MAN_DEVICE_MANAGEMENT;
     107         [ +  + ]:         12 :         if (hapd->conf->p2p & P2P_ALLOW_CROSS_CONNECTION)
     108                 :          6 :                 bitmap |= P2P_MAN_CROSS_CONNECTION_PERMITTED;
     109                 :         12 :         bitmap |= P2P_MAN_COEXISTENCE_OPTIONAL;
     110                 :         12 :         *eid++ = bitmap;
     111                 :            : 
     112                 :         12 :         return eid;
     113                 :            : }
     114                 :            : #endif /* CONFIG_P2P_MANAGER */

Generated by: LCOV version 1.9