1*71e72c9eSCy Schubert /* 2*71e72c9eSCy Schubert * Proxmity Ranging 3*71e72c9eSCy Schubert * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 4*71e72c9eSCy Schubert * 5*71e72c9eSCy Schubert * This software may be distributed under the terms of the BSD license. 6*71e72c9eSCy Schubert * See README for more details. 7*71e72c9eSCy Schubert */ 8*71e72c9eSCy Schubert 9*71e72c9eSCy Schubert #ifndef PROXIMITY_RANGING_H 10*71e72c9eSCy Schubert #define PROXIMITY_RANGING_H 11*71e72c9eSCy Schubert 12*71e72c9eSCy Schubert #include "wpa_common.h" 13*71e72c9eSCy Schubert #include "utils/list.h" 14*71e72c9eSCy Schubert #include "wps/wps_defs.h" 15*71e72c9eSCy Schubert 16*71e72c9eSCy Schubert struct ieee80211_mgmt; 17*71e72c9eSCy Schubert 18*71e72c9eSCy Schubert #define DEVICE_IDENTITY_KEY_LEN 16 19*71e72c9eSCy Schubert #define DEVICE_IDENTITY_TAG_LEN 8 20*71e72c9eSCy Schubert #define DEVICE_IDENTITY_NONCE_LEN 8 21*71e72c9eSCy Schubert #define DIR_STR_LEN 3 22*71e72c9eSCy Schubert #define DEVICE_MAX_HASH_LEN 32 23*71e72c9eSCy Schubert 24*71e72c9eSCy Schubert /* DIRA Cipher versions */ 25*71e72c9eSCy Schubert #define DIRA_CIPHER_VERSION_128 0 26*71e72c9eSCy Schubert 27*71e72c9eSCy Schubert /** 28*71e72c9eSCy Schubert * PR_MAX_OP_CLASSES - Maximum number of operating classes 29*71e72c9eSCy Schubert */ 30*71e72c9eSCy Schubert #define PR_MAX_OP_CLASSES 30 31*71e72c9eSCy Schubert 32*71e72c9eSCy Schubert /** 33*71e72c9eSCy Schubert * PR_MAX_OP_CLASS_CHANNELS - Maximum number of channels per operating class 34*71e72c9eSCy Schubert */ 35*71e72c9eSCy Schubert #define PR_MAX_OP_CLASS_CHANNELS 60 36*71e72c9eSCy Schubert 37*71e72c9eSCy Schubert /** 38*71e72c9eSCy Schubert * PR_MAX_PEER - Maximum number of Proximity Ranging peers that device can store 39*71e72c9eSCy Schubert */ 40*71e72c9eSCy Schubert #define PR_MAX_PEER 100 41*71e72c9eSCy Schubert 42*71e72c9eSCy Schubert /* 43*71e72c9eSCy Schubert * Proximity Ranging negotiation status 44*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation D1.8, 45*71e72c9eSCy Schubert * Table 5 (Proximity Ranging Status Attribute format). 46*71e72c9eSCy Schubert */ 47*71e72c9eSCy Schubert #define PR_NEGOTIATION_SUCCESS 0 48*71e72c9eSCy Schubert #define PR_NEGOTIATION_UPDATE 1 49*71e72c9eSCy Schubert #define PR_NEGOTIATION_FAIL 2 50*71e72c9eSCy Schubert 51*71e72c9eSCy Schubert /** 52*71e72c9eSCy Schubert * enum pr_session_end_reason - Reason codes for ranging session end 53*71e72c9eSCy Schubert */ 54*71e72c9eSCy Schubert enum pr_session_end_reason { 55*71e72c9eSCy Schubert PR_SESSION_END_TIMEOUT = 0, 56*71e72c9eSCy Schubert PR_SESSION_END_USER_ABORT = 1, 57*71e72c9eSCy Schubert PR_SESSION_END_PEER_COMPLETE = 2, 58*71e72c9eSCy Schubert PR_SESSION_END_NEG_FAILED = 3, 59*71e72c9eSCy Schubert }; 60*71e72c9eSCy Schubert 61*71e72c9eSCy Schubert enum pr_pasn_role { 62*71e72c9eSCy Schubert PR_ROLE_IDLE = 0, 63*71e72c9eSCy Schubert PR_ROLE_PASN_INITIATOR, 64*71e72c9eSCy Schubert PR_ROLE_PASN_RESPONDER, 65*71e72c9eSCy Schubert }; 66*71e72c9eSCy Schubert 67*71e72c9eSCy Schubert /** 68*71e72c9eSCy Schubert * struct pr_channels - List of supported channels 69*71e72c9eSCy Schubert */ 70*71e72c9eSCy Schubert struct pr_channels { 71*71e72c9eSCy Schubert /** 72*71e72c9eSCy Schubert * struct pr_op_class - Supported operating class 73*71e72c9eSCy Schubert */ 74*71e72c9eSCy Schubert struct pr_op_class { 75*71e72c9eSCy Schubert /** 76*71e72c9eSCy Schubert * op_class - Operating class 77*71e72c9eSCy Schubert */ 78*71e72c9eSCy Schubert u8 op_class; 79*71e72c9eSCy Schubert 80*71e72c9eSCy Schubert /** 81*71e72c9eSCy Schubert * channel - Supported channels 82*71e72c9eSCy Schubert */ 83*71e72c9eSCy Schubert u8 channel[PR_MAX_OP_CLASS_CHANNELS]; 84*71e72c9eSCy Schubert 85*71e72c9eSCy Schubert /** 86*71e72c9eSCy Schubert * channels - Number of channel entries in use 87*71e72c9eSCy Schubert */ 88*71e72c9eSCy Schubert size_t channels; 89*71e72c9eSCy Schubert } op_class[PR_MAX_OP_CLASSES]; 90*71e72c9eSCy Schubert 91*71e72c9eSCy Schubert /** 92*71e72c9eSCy Schubert * op_classes - Number of op_class entries in use 93*71e72c9eSCy Schubert */ 94*71e72c9eSCy Schubert size_t op_classes; 95*71e72c9eSCy Schubert }; 96*71e72c9eSCy Schubert 97*71e72c9eSCy Schubert /** 98*71e72c9eSCy Schubert * Format and Bandwidth values for EDCA based ranging with range of 10-16 99*71e72c9eSCy Schubert * from IEEE Std 802.11-2024, 9.4.2.166 (FTM Parameters element), Table 9-325 100*71e72c9eSCy Schubert * (Format And Bandwidth subfield) as specified in Proximity Ranging 101*71e72c9eSCy Schubert * Implementation Considerations for P2P Operation, Draft 1.8, Table 8 102*71e72c9eSCy Schubert * (Proximity Ranging EDCA Capability Attribute format) for the the Ranging 103*71e72c9eSCy Schubert * Parameters field B0-B3. 104*71e72c9eSCy Schubert */ 105*71e72c9eSCy Schubert enum edca_format_and_bw_value { 106*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT20 = 10, 107*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_HT40 = 11, 108*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT40 = 12, 109*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT80 = 13, 110*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT80P80 = 14, 111*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT160_DUAL_LO = 15, 112*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_VHT160_SINGLE_LO = 16, 113*71e72c9eSCy Schubert EDCA_FORMAT_AND_BW_INVALID 114*71e72c9eSCy Schubert }; 115*71e72c9eSCy Schubert 116*71e72c9eSCy Schubert /** 117*71e72c9eSCy Schubert * Format and Bandwidth values for NTB based ranging as from IEEE Std 118*71e72c9eSCy Schubert * 802.11-2024, 9.4.2.300 (Ranging Parameters element), Table 9-412 (Format And 119*71e72c9eSCy Schubert * Bandwidth subfield) as specified in Proximity Ranging Implementation 120*71e72c9eSCy Schubert * Considerations for P2P Operation, Draft 1.8, Table 9 (Proximity Ranging 11az 121*71e72c9eSCy Schubert * NTB Capability Attribute format) for the Ranging Parameter field B0-B2. 122*71e72c9eSCy Schubert */ 123*71e72c9eSCy Schubert enum ntb_format_and_bw_value { 124*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE20 = 0, 125*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE40 = 1, 126*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE80 = 2, 127*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE80P80 = 3, 128*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE160_DUAL_LO = 4, 129*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_HE160_SINGLE_LO = 5, 130*71e72c9eSCy Schubert NTB_FORMAT_AND_BW_INVALID 131*71e72c9eSCy Schubert }; 132*71e72c9eSCy Schubert 133*71e72c9eSCy Schubert struct pr_capabilities { 134*71e72c9eSCy Schubert u8 pasn_type; 135*71e72c9eSCy Schubert 136*71e72c9eSCy Schubert char device_name[WPS_DEV_NAME_MAX_LEN + 1]; 137*71e72c9eSCy Schubert 138*71e72c9eSCy Schubert bool edca_support; 139*71e72c9eSCy Schubert 140*71e72c9eSCy Schubert bool ntb_support; 141*71e72c9eSCy Schubert 142*71e72c9eSCy Schubert bool secure_he_ltf; 143*71e72c9eSCy Schubert 144*71e72c9eSCy Schubert bool support_6ghz; 145*71e72c9eSCy Schubert }; 146*71e72c9eSCy Schubert 147*71e72c9eSCy Schubert struct edca_capabilities { 148*71e72c9eSCy Schubert bool ista_support; 149*71e72c9eSCy Schubert 150*71e72c9eSCy Schubert bool rsta_support; 151*71e72c9eSCy Schubert 152*71e72c9eSCy Schubert /** 153*71e72c9eSCy Schubert * Ranging Parameters field for device specific EDCA capabilities 154*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation Draft 1.8, 155*71e72c9eSCy Schubert * Table 8 (Proximity Ranging EDCA Capability Attribute format). 156*71e72c9eSCy Schubert */ 157*71e72c9eSCy Schubert #define EDCA_FORMAT_AND_BW 0 158*71e72c9eSCy Schubert #define EDCA_MAX_TX_ANTENNA 4 159*71e72c9eSCy Schubert #define EDCA_MAX_RX_ANTENNA 7 160*71e72c9eSCy Schubert 161*71e72c9eSCy Schubert #define EDCA_FORMAT_AND_BW_MASK 0x000F 162*71e72c9eSCy Schubert #define EDCA_MAX_TX_ANTENNA_MASK 0x0007 163*71e72c9eSCy Schubert #define EDCA_MAX_RX_ANTENNA_MASK 0x0007 164*71e72c9eSCy Schubert u16 edca_hw_caps; 165*71e72c9eSCy Schubert 166*71e72c9eSCy Schubert char country[3]; 167*71e72c9eSCy Schubert 168*71e72c9eSCy Schubert struct pr_channels channels; 169*71e72c9eSCy Schubert }; 170*71e72c9eSCy Schubert 171*71e72c9eSCy Schubert struct ntb_capabilities { 172*71e72c9eSCy Schubert bool ista_support; 173*71e72c9eSCy Schubert 174*71e72c9eSCy Schubert bool rsta_support; 175*71e72c9eSCy Schubert 176*71e72c9eSCy Schubert bool secure_he_ltf; 177*71e72c9eSCy Schubert 178*71e72c9eSCy Schubert /** 179*71e72c9eSCy Schubert * Ranging Parameter field for NTB capabilities 180*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation Draft 1.8, 181*71e72c9eSCy Schubert * Table 9 (Proximity Ranging 11az NTB Capability Attribute format). 182*71e72c9eSCy Schubert */ 183*71e72c9eSCy Schubert #define NTB_FORMAT_AND_BW 0 184*71e72c9eSCy Schubert #define MAX_TX_LTF_REPETATIONS 3 185*71e72c9eSCy Schubert #define MAX_RX_LTF_REPETATIONS 6 186*71e72c9eSCy Schubert #define MAX_RX_LTF_TOTAL 9 187*71e72c9eSCy Schubert #define MAX_TX_LTF_TOTAL 11 188*71e72c9eSCy Schubert #define MAX_RX_STS_LE_80 13 189*71e72c9eSCy Schubert #define MAX_RX_STS_GT_80 16 190*71e72c9eSCy Schubert #define MAX_TX_STS_LE_80 19 191*71e72c9eSCy Schubert #define MAX_TX_STS_GT_80 22 192*71e72c9eSCy Schubert 193*71e72c9eSCy Schubert #define NTB_FORMAT_AND_BW_MASK 0x00000007 194*71e72c9eSCy Schubert 195*71e72c9eSCy Schubert /* Max TX LTF repetations supported for non trigger based ranging */ 196*71e72c9eSCy Schubert #define MAX_TX_LTF_REPETATIONS_MASK 0x00000007 197*71e72c9eSCy Schubert 198*71e72c9eSCy Schubert /* Max RX LTF repetations supported for non trigger based ranging */ 199*71e72c9eSCy Schubert #define MAX_RX_LTF_REPETATIONS_MASK 0x00000007 200*71e72c9eSCy Schubert 201*71e72c9eSCy Schubert /* Max RX LTF total supported for non trigger based ranging */ 202*71e72c9eSCy Schubert #define MAX_RX_LTF_TOTAL_MASK 0x00000003 203*71e72c9eSCy Schubert 204*71e72c9eSCy Schubert /* Max TX LTF total supported for non trigger based ranging */ 205*71e72c9eSCy Schubert #define MAX_TX_LTF_TOTAL_MASK 0x00000003 206*71e72c9eSCy Schubert 207*71e72c9eSCy Schubert /* To configure max R2I STS for Bandwidth less than or equal to 80 MHz */ 208*71e72c9eSCy Schubert #define MAX_RX_STS_LE_80_MASK 0x00000007 209*71e72c9eSCy Schubert 210*71e72c9eSCy Schubert /* To configure max R2I STS for Bandwidth greater than 80Mz */ 211*71e72c9eSCy Schubert #define MAX_RX_STS_GT_80_MASK 0x00000007 212*71e72c9eSCy Schubert 213*71e72c9eSCy Schubert /* To configure max I2R STS for Bandwidth less than or equal to 80 MHz */ 214*71e72c9eSCy Schubert #define MAX_TX_STS_LE_80_MASK 0x00000007 215*71e72c9eSCy Schubert 216*71e72c9eSCy Schubert /* To configure max I2R STS for Bandwidth greater than 80 MHz */ 217*71e72c9eSCy Schubert #define MAX_TX_STS_GT_80_MASK 0x00000007 218*71e72c9eSCy Schubert u32 ntb_hw_caps; 219*71e72c9eSCy Schubert 220*71e72c9eSCy Schubert char country[3]; 221*71e72c9eSCy Schubert 222*71e72c9eSCy Schubert struct pr_channels channels; 223*71e72c9eSCy Schubert }; 224*71e72c9eSCy Schubert 225*71e72c9eSCy Schubert /* 226*71e72c9eSCy Schubert * Proximity Ranging Attribute IDs 227*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation Draft 1.8, 228*71e72c9eSCy Schubert * Table 4 (Proximity Ranging Attribute ID list). 229*71e72c9eSCy Schubert */ 230*71e72c9eSCy Schubert enum pr_attr_id { 231*71e72c9eSCy Schubert PR_ATTR_STATUS = 0, 232*71e72c9eSCy Schubert PR_ATTR_RANGING_CAPABILITY = 1, 233*71e72c9eSCy Schubert PR_ATTR_EDCA_CAPABILITY = 2, 234*71e72c9eSCy Schubert PR_ATTR_NTB_CAPABILITY = 3, 235*71e72c9eSCy Schubert PR_ATTR_OPERATION_MODE = 4, 236*71e72c9eSCy Schubert PR_ATTR_WLAN_AP_INFO = 5, 237*71e72c9eSCy Schubert PR_ATTR_DEVICE_IDENTITY_RESOLUTION = 6, 238*71e72c9eSCy Schubert PR_ATTR_VENDOR_SPECIFIC = 221, 239*71e72c9eSCy Schubert }; 240*71e72c9eSCy Schubert 241*71e72c9eSCy Schubert /* 242*71e72c9eSCy Schubert * Proximity Ranging capabilities in Ranging Protocol Type field, 243*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation Draft 1.8, 244*71e72c9eSCy Schubert * Table 7 (Proximity Ranging Capability Attribute format). 245*71e72c9eSCy Schubert */ 246*71e72c9eSCy Schubert #define PR_EDCA_BASED_RANGING BIT(0) 247*71e72c9eSCy Schubert #define PR_NTB_SECURE_LTF_BASED_RANGING BIT(1) 248*71e72c9eSCy Schubert #define PR_NTB_OPEN_BASED_RANGING BIT(2) 249*71e72c9eSCy Schubert 250*71e72c9eSCy Schubert /** 251*71e72c9eSCy Schubert * Ranging Role field in EDCA capabilities 252*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation Draft 1.8, 253*71e72c9eSCy Schubert * Table 8 (Proximity Ranging EDCA Capability Attribute format). 254*71e72c9eSCy Schubert */ 255*71e72c9eSCy Schubert #define PR_ISTA_SUPPORT BIT(0) 256*71e72c9eSCy Schubert #define PR_RSTA_SUPPORT BIT(1) 257*71e72c9eSCy Schubert 258*71e72c9eSCy Schubert /* 259*71e72c9eSCy Schubert * PASN capabilities in PASN Type field 260*71e72c9eSCy Schubert * Proximity Ranging Implementation Considerations for P2P Operation D1.8, 261*71e72c9eSCy Schubert * Table 7 (Proximity Ranging Capability Attribute). 262*71e72c9eSCy Schubert */ 263*71e72c9eSCy Schubert #define PR_PASN_DH19_UNAUTH BIT(0) 264*71e72c9eSCy Schubert #define PR_PASN_DH19_AUTH BIT(1) 265*71e72c9eSCy Schubert #define PR_PASN_DH20_UNAUTH BIT(2) 266*71e72c9eSCy Schubert #define PR_PASN_DH20_AUTH BIT(3) 267*71e72c9eSCy Schubert 268*71e72c9eSCy Schubert /* Authentication Mode */ 269*71e72c9eSCy Schubert #define PR_PASN_AUTH_MODE_PASN 0 270*71e72c9eSCy Schubert #define PR_PASN_AUTH_MODE_SAE 1 271*71e72c9eSCy Schubert #define PR_PASN_AUTH_MODE_PMK 2 272*71e72c9eSCy Schubert 273*71e72c9eSCy Schubert /* Peer discovery type */ 274*71e72c9eSCy Schubert #define PR_DISCOVERY_TYPE_USD 0 275*71e72c9eSCy Schubert #define PR_DISCOVERY_TYPE_OOB 1 276*71e72c9eSCy Schubert 277*71e72c9eSCy Schubert /** 278*71e72c9eSCy Schubert * struct pr_pasn_ranging_params - Peer parameters to be used in PASN to trigger 279*71e72c9eSCy Schubert * ranging in case PR PASN is successful. 280*71e72c9eSCy Schubert */ 281*71e72c9eSCy Schubert struct pr_pasn_ranging_params { 282*71e72c9eSCy Schubert enum { 283*71e72c9eSCy Schubert PR_PASN_AND_RANGING, 284*71e72c9eSCy Schubert PR_STOP_RANGING, 285*71e72c9eSCy Schubert } action; 286*71e72c9eSCy Schubert u8 peer_addr[ETH_ALEN]; 287*71e72c9eSCy Schubert u8 ranging_type; 288*71e72c9eSCy Schubert u8 ranging_role; 289*71e72c9eSCy Schubert u8 pr_pasn_status; 290*71e72c9eSCy Schubert u8 auth_mode; 291*71e72c9eSCy Schubert int freq; 292*71e72c9eSCy Schubert u32 ranging_timeout; 293*71e72c9eSCy Schubert u8 src_addr[ETH_ALEN]; 294*71e72c9eSCy Schubert enum pr_pasn_role pasn_role; 295*71e72c9eSCy Schubert 296*71e72c9eSCy Schubert /** 297*71e72c9eSCy Schubert * EDCA based ranging specific parameters 298*71e72c9eSCy Schubert * 299*71e72c9eSCy Schubert * @burst_period: Burst period in units of 100 milliseconds 300*71e72c9eSCy Schubert * @num_bursts_exp: Number of bursts exponent 301*71e72c9eSCy Schubert * @ftms_per_burst: Number of FTM frames per burst 302*71e72c9eSCy Schubert * @ftmr_retries: Number of retries for FTM Request frame 303*71e72c9eSCy Schubert * @burst_duration: Burst duration as defined in IEEE Std 802.11-2024, 304*71e72c9eSCy Schubert * Table 9-322 (Burst Duration subfield encoding). 305*71e72c9eSCy Schubert */ 306*71e72c9eSCy Schubert u16 burst_period; 307*71e72c9eSCy Schubert u8 num_bursts_exp; 308*71e72c9eSCy Schubert u8 ftms_per_burst; 309*71e72c9eSCy Schubert u8 ftmr_retries; 310*71e72c9eSCy Schubert u8 burst_duration; 311*71e72c9eSCy Schubert 312*71e72c9eSCy Schubert /** 313*71e72c9eSCy Schubert * NTB ranging specific parameters 314*71e72c9eSCy Schubert * 315*71e72c9eSCy Schubert * @min_time_between_measurements: Minimum time between two consecutive 316*71e72c9eSCy Schubert * range measurements in units of 100 microseconds. 317*71e72c9eSCy Schubert * @max_time_between_measurements: Maximum time between two consecutive 318*71e72c9eSCy Schubert * range measurements in units of 10 milliseconds, to avoid FTM 319*71e72c9eSCy Schubert * negotiation. 320*71e72c9eSCy Schubert * @availability_window: Duration of the Availability Window (AW) in 321*71e72c9eSCy Schubert * units of 1 millisecond (0-255 ms). 322*71e72c9eSCy Schubert * @nominal_time: Nominal duration between adjacent Availability Windows 323*71e72c9eSCy Schubert * in units of milliseconds. 324*71e72c9eSCy Schubert */ 325*71e72c9eSCy Schubert u32 min_time_between_measurements; 326*71e72c9eSCy Schubert u32 max_time_between_measurements; 327*71e72c9eSCy Schubert u8 availability_window; 328*71e72c9eSCy Schubert u32 nominal_time; 329*71e72c9eSCy Schubert 330*71e72c9eSCy Schubert /** 331*71e72c9eSCy Schubert * @request_lci: Whether to request LCI 332*71e72c9eSCy Schubert * @request_civicloc: Whether to request civic location 333*71e72c9eSCy Schubert */ 334*71e72c9eSCy Schubert bool request_lci; 335*71e72c9eSCy Schubert bool request_civicloc; 336*71e72c9eSCy Schubert 337*71e72c9eSCy Schubert /** 338*71e72c9eSCy Schubert * @lmr_feedback: Negotiate LMR feedback for NTB ranging. 339*71e72c9eSCy Schubert * Only valid when NTB ranging type is set. Required for RSTA 340*71e72c9eSCy Schubert * to report measurement results back to the initiator. 341*71e72c9eSCy Schubert */ 342*71e72c9eSCy Schubert bool lmr_feedback; 343*71e72c9eSCy Schubert 344*71e72c9eSCy Schubert /** 345*71e72c9eSCy Schubert * @ingress_threshold: Ingress range threshold in millimeters. 346*71e72c9eSCy Schubert * The kernel reports a measurement result when the device 347*71e72c9eSCy Schubert * moves into this range. 348*71e72c9eSCy Schubert */ 349*71e72c9eSCy Schubert u64 ingress_threshold; 350*71e72c9eSCy Schubert 351*71e72c9eSCy Schubert /** 352*71e72c9eSCy Schubert * @egress_threshold: Egress range threshold in millimeters. 353*71e72c9eSCy Schubert * The kernel reports a measurement result when the device 354*71e72c9eSCy Schubert * moves out of this range. 355*71e72c9eSCy Schubert */ 356*71e72c9eSCy Schubert u64 egress_threshold; 357*71e72c9eSCy Schubert 358*71e72c9eSCy Schubert /** 359*71e72c9eSCy Schubert * @pr_suppress_results: Suppress ranging results for PD requests. 360*71e72c9eSCy Schubert * Cannot be used with range_report or lmr_feedback. 361*71e72c9eSCy Schubert */ 362*71e72c9eSCy Schubert bool pr_suppress_results; 363*71e72c9eSCy Schubert 364*71e72c9eSCy Schubert u32 continuous_ranging_session_time; 365*71e72c9eSCy Schubert 366*71e72c9eSCy Schubert int forced_pr_freq; 367*71e72c9eSCy Schubert u8 ranging_op_class; 368*71e72c9eSCy Schubert u16 channel_width; /* channel width in MHz (20/40/80/160/320) */ 369*71e72c9eSCy Schubert u8 format_bw; 370*71e72c9eSCy Schubert u32 center_freq1; 371*71e72c9eSCy Schubert u32 center_freq2; 372*71e72c9eSCy Schubert u64 cookie; 373*71e72c9eSCy Schubert 374*71e72c9eSCy Schubert /* Per-session credentials - if set, used instead of stored ones */ 375*71e72c9eSCy Schubert char password[100]; 376*71e72c9eSCy Schubert bool password_valid; 377*71e72c9eSCy Schubert u8 pmk[PMK_LEN_MAX]; 378*71e72c9eSCy Schubert size_t pmk_len; 379*71e72c9eSCy Schubert }; 380*71e72c9eSCy Schubert 381*71e72c9eSCy Schubert struct pr_dev_ik { 382*71e72c9eSCy Schubert struct dl_list list; 383*71e72c9eSCy Schubert u8 dik[DEVICE_IDENTITY_KEY_LEN]; 384*71e72c9eSCy Schubert char password[100]; 385*71e72c9eSCy Schubert bool password_valid; 386*71e72c9eSCy Schubert u8 pmk[PMK_LEN_MAX]; 387*71e72c9eSCy Schubert size_t pmk_len; 388*71e72c9eSCy Schubert bool pmk_valid; 389*71e72c9eSCy Schubert }; 390*71e72c9eSCy Schubert 391*71e72c9eSCy Schubert /** 392*71e72c9eSCy Schubert * struct pr_device_info - Proximity ranging peer information 393*71e72c9eSCy Schubert */ 394*71e72c9eSCy Schubert struct pr_device { 395*71e72c9eSCy Schubert struct dl_list list; 396*71e72c9eSCy Schubert struct os_reltime last_seen; 397*71e72c9eSCy Schubert int listen_freq; 398*71e72c9eSCy Schubert 399*71e72c9eSCy Schubert /** 400*71e72c9eSCy Schubert * pr_device_addr - PR Device Address of the peer 401*71e72c9eSCy Schubert */ 402*71e72c9eSCy Schubert u8 pr_device_addr[ETH_ALEN]; 403*71e72c9eSCy Schubert 404*71e72c9eSCy Schubert struct pr_capabilities pr_caps; 405*71e72c9eSCy Schubert struct edca_capabilities edca_caps; 406*71e72c9eSCy Schubert struct ntb_capabilities ntb_caps; 407*71e72c9eSCy Schubert 408*71e72c9eSCy Schubert /* Password to be used in PASN-SAE by the Seeker. 409*71e72c9eSCy Schubert * This is updated with valid password if DIRA matches for the peer. 410*71e72c9eSCy Schubert */ 411*71e72c9eSCy Schubert char password[100]; 412*71e72c9eSCy Schubert bool password_valid; 413*71e72c9eSCy Schubert 414*71e72c9eSCy Schubert /* PMK to be used in PASN-PMK by the Seeker. 415*71e72c9eSCy Schubert * This is updated with valid PMK if DIRA matches for the peer. 416*71e72c9eSCy Schubert */ 417*71e72c9eSCy Schubert u8 pmk[PMK_LEN_MAX]; 418*71e72c9eSCy Schubert size_t pmk_len; 419*71e72c9eSCy Schubert bool pmk_valid; 420*71e72c9eSCy Schubert 421*71e72c9eSCy Schubert /* DevIK of the peer resolved via DIRA verification. 422*71e72c9eSCy Schubert * Set to the matched dev_ik->dik when pr_validate_dira() succeeds. 423*71e72c9eSCy Schubert * Cleared by pr_clear_dev_iks(). 424*71e72c9eSCy Schubert */ 425*71e72c9eSCy Schubert u8 dik[DEVICE_IDENTITY_KEY_LEN]; 426*71e72c9eSCy Schubert bool dik_valid; 427*71e72c9eSCy Schubert 428*71e72c9eSCy Schubert #ifdef CONFIG_PASN 429*71e72c9eSCy Schubert /* PASN data structure */ 430*71e72c9eSCy Schubert struct pasn_data *pasn; 431*71e72c9eSCy Schubert struct wpabuf *ranging_wrapper; 432*71e72c9eSCy Schubert enum pr_pasn_role pasn_role; 433*71e72c9eSCy Schubert #endif /* CONFIG_PASN */ 434*71e72c9eSCy Schubert 435*71e72c9eSCy Schubert u8 ranging_role; 436*71e72c9eSCy Schubert u8 protocol_type; 437*71e72c9eSCy Schubert u8 final_op_class; 438*71e72c9eSCy Schubert u8 final_op_channel; 439*71e72c9eSCy Schubert u8 discovery_type; 440*71e72c9eSCy Schubert }; 441*71e72c9eSCy Schubert 442*71e72c9eSCy Schubert 443*71e72c9eSCy Schubert /** 444*71e72c9eSCy Schubert * struct pr_message - Proximity ranging peer information 445*71e72c9eSCy Schubert */ 446*71e72c9eSCy Schubert struct pr_message { 447*71e72c9eSCy Schubert struct wpabuf *pr_attributes; 448*71e72c9eSCy Schubert 449*71e72c9eSCy Schubert u8 pr_device_addr[ETH_ALEN]; 450*71e72c9eSCy Schubert 451*71e72c9eSCy Schubert const u8 *pr_capability; 452*71e72c9eSCy Schubert size_t pr_capability_len; 453*71e72c9eSCy Schubert 454*71e72c9eSCy Schubert const u8 *edca_capability; 455*71e72c9eSCy Schubert size_t edca_capability_len; 456*71e72c9eSCy Schubert 457*71e72c9eSCy Schubert const u8 *ntb_capability; 458*71e72c9eSCy Schubert size_t ntb_capability_len; 459*71e72c9eSCy Schubert 460*71e72c9eSCy Schubert const u8 *dira; 461*71e72c9eSCy Schubert size_t dira_len; 462*71e72c9eSCy Schubert 463*71e72c9eSCy Schubert const u8 *status_ie; 464*71e72c9eSCy Schubert size_t status_ie_len; 465*71e72c9eSCy Schubert 466*71e72c9eSCy Schubert const u8 *op_mode; 467*71e72c9eSCy Schubert size_t op_mode_len; 468*71e72c9eSCy Schubert }; 469*71e72c9eSCy Schubert 470*71e72c9eSCy Schubert 471*71e72c9eSCy Schubert struct pr_config { 472*71e72c9eSCy Schubert u8 pasn_type; 473*71e72c9eSCy Schubert 474*71e72c9eSCy Schubert int preferred_ranging_role; 475*71e72c9eSCy Schubert 476*71e72c9eSCy Schubert char country[3]; 477*71e72c9eSCy Schubert 478*71e72c9eSCy Schubert u8 dev_addr[ETH_ALEN]; 479*71e72c9eSCy Schubert 480*71e72c9eSCy Schubert /** 481*71e72c9eSCy Schubert * dev_name - Device Name 482*71e72c9eSCy Schubert */ 483*71e72c9eSCy Schubert char *dev_name; 484*71e72c9eSCy Schubert 485*71e72c9eSCy Schubert bool edca_ista_support; 486*71e72c9eSCy Schubert 487*71e72c9eSCy Schubert bool edca_rsta_support; 488*71e72c9eSCy Schubert 489*71e72c9eSCy Schubert /* Best single format_bw value derived from pd_format_bw_bitmap */ 490*71e72c9eSCy Schubert u8 edca_format_and_bw; 491*71e72c9eSCy Schubert 492*71e72c9eSCy Schubert u32 edca_min_ranging_interval; 493*71e72c9eSCy Schubert 494*71e72c9eSCy Schubert u8 max_tx_antenna; 495*71e72c9eSCy Schubert 496*71e72c9eSCy Schubert u8 max_rx_antenna; 497*71e72c9eSCy Schubert 498*71e72c9eSCy Schubert struct pr_channels edca_channels; 499*71e72c9eSCy Schubert 500*71e72c9eSCy Schubert bool ntb_ista_support; 501*71e72c9eSCy Schubert 502*71e72c9eSCy Schubert bool ntb_rsta_support; 503*71e72c9eSCy Schubert 504*71e72c9eSCy Schubert bool concurrent_ista_rsta; 505*71e72c9eSCy Schubert 506*71e72c9eSCy Schubert u32 pmsr_max_peers; 507*71e72c9eSCy Schubert 508*71e72c9eSCy Schubert u32 pr_max_peer_ista_role; 509*71e72c9eSCy Schubert 510*71e72c9eSCy Schubert u32 pr_max_peer_rsta_role; 511*71e72c9eSCy Schubert 512*71e72c9eSCy Schubert u8 max_ftms_per_burst; 513*71e72c9eSCy Schubert 514*71e72c9eSCy Schubert bool secure_he_ltf; 515*71e72c9eSCy Schubert 516*71e72c9eSCy Schubert u8 max_tx_ltf_repetations; 517*71e72c9eSCy Schubert 518*71e72c9eSCy Schubert u8 max_rx_ltf_repetations; 519*71e72c9eSCy Schubert 520*71e72c9eSCy Schubert u8 max_tx_ltf_total; 521*71e72c9eSCy Schubert 522*71e72c9eSCy Schubert u8 max_rx_ltf_total; 523*71e72c9eSCy Schubert 524*71e72c9eSCy Schubert u8 max_rx_sts_le_80; 525*71e72c9eSCy Schubert 526*71e72c9eSCy Schubert u8 max_rx_sts_gt_80; 527*71e72c9eSCy Schubert 528*71e72c9eSCy Schubert u8 max_tx_sts_le_80; 529*71e72c9eSCy Schubert 530*71e72c9eSCy Schubert u8 max_tx_sts_gt_80; 531*71e72c9eSCy Schubert 532*71e72c9eSCy Schubert /* PD ranging preamble and bandwidth bitmaps (shared by EDCA and NTB) */ 533*71e72c9eSCy Schubert u32 pd_preamble_bitmap; 534*71e72c9eSCy Schubert u32 pd_format_bw_bitmap; 535*71e72c9eSCy Schubert 536*71e72c9eSCy Schubert /* Best single format_bw value derived from pd_format_bw_bitmap */ 537*71e72c9eSCy Schubert u8 ntb_format_and_bw; 538*71e72c9eSCy Schubert 539*71e72c9eSCy Schubert u32 ntb_min_ranging_interval; 540*71e72c9eSCy Schubert 541*71e72c9eSCy Schubert struct pr_channels ntb_channels; 542*71e72c9eSCy Schubert 543*71e72c9eSCy Schubert bool support_6ghz; 544*71e72c9eSCy Schubert 545*71e72c9eSCy Schubert /* Cipher version type */ 546*71e72c9eSCy Schubert int dik_cipher; 547*71e72c9eSCy Schubert 548*71e72c9eSCy Schubert /* Buffer to hold the DevIK */ 549*71e72c9eSCy Schubert u8 dik_data[DEVICE_IDENTITY_KEY_LEN]; 550*71e72c9eSCy Schubert 551*71e72c9eSCy Schubert /* Length of DevIK in octets */ 552*71e72c9eSCy Schubert size_t dik_len; 553*71e72c9eSCy Schubert 554*71e72c9eSCy Schubert /* DevIK expiration */ 555*71e72c9eSCy Schubert int expiration; 556*71e72c9eSCy Schubert 557*71e72c9eSCy Schubert /* Global password to be used in PASN-SAE for Advertiser */ 558*71e72c9eSCy Schubert char global_password[100]; 559*71e72c9eSCy Schubert 560*71e72c9eSCy Schubert bool global_password_valid; 561*71e72c9eSCy Schubert 562*71e72c9eSCy Schubert /** 563*71e72c9eSCy Schubert * cb_ctx - Context to use with callback functions 564*71e72c9eSCy Schubert */ 565*71e72c9eSCy Schubert void *cb_ctx; 566*71e72c9eSCy Schubert 567*71e72c9eSCy Schubert /** 568*71e72c9eSCy Schubert * pasn_send_mgmt - Function handler to transmit a Management frame 569*71e72c9eSCy Schubert * @ctx: Callback context from cb_ctx 570*71e72c9eSCy Schubert * @data: Frame to transmit 571*71e72c9eSCy Schubert * @data_len: Length of frame to transmit 572*71e72c9eSCy Schubert * @noack: No ack flag 573*71e72c9eSCy Schubert * @freq: Frequency in MHz for the channel on which to transmit 574*71e72c9eSCy Schubert * @wait: How many milliseconds to wait for a response frame 575*71e72c9eSCy Schubert * Returns: 0 on success, -1 on failure 576*71e72c9eSCy Schubert */ 577*71e72c9eSCy Schubert int (*pasn_send_mgmt)(void *ctx, const u8 *data, size_t data_len, 578*71e72c9eSCy Schubert int noack, unsigned int freq, unsigned int wait); 579*71e72c9eSCy Schubert 580*71e72c9eSCy Schubert /** 581*71e72c9eSCy Schubert * negotiation_started - Called when PASN negotiation begins 582*71e72c9eSCy Schubert * @ctx: Callback context from cb_ctx 583*71e72c9eSCy Schubert * @peer_addr: MAC address of the peer 584*71e72c9eSCy Schubert * @role: Ranging role (initiator or responder) 585*71e72c9eSCy Schubert * @protocol_type: Ranging protocol type 586*71e72c9eSCy Schubert * 587*71e72c9eSCy Schubert * Fired on the initiator after Auth frame 1 (M1) is sent, and on the 588*71e72c9eSCy Schubert * responder after Auth frame 1 (M1) is received and M2 is sent back. 589*71e72c9eSCy Schubert */ 590*71e72c9eSCy Schubert void (*negotiation_started)(void *ctx, const u8 *peer_addr, u8 role, 591*71e72c9eSCy Schubert u8 protocol_type); 592*71e72c9eSCy Schubert 593*71e72c9eSCy Schubert void (*pasn_result)(void *ctx, u8 role, u8 protocol_type, u8 op_class, 594*71e72c9eSCy Schubert u8 op_channel, const char *country); 595*71e72c9eSCy Schubert 596*71e72c9eSCy Schubert int (*set_keys)(void *ctx, const u8 *own_addr, const u8 *peer_addr, 597*71e72c9eSCy Schubert int cipher, int akmp, struct wpa_ptk *ptk); 598*71e72c9eSCy Schubert 599*71e72c9eSCy Schubert void (*clear_keys)(void *ctx, const u8 *own_addr, const u8 *peer_addr); 600*71e72c9eSCy Schubert 601*71e72c9eSCy Schubert void (*get_ranging_params)(void *ctx, const u8 *dev_addr, 602*71e72c9eSCy Schubert const u8 *peer_addr, u8 ranging_role, 603*71e72c9eSCy Schubert u8 protocol_type, u8 op_class, u8 op_channel, 604*71e72c9eSCy Schubert u8 self_format_bw, u8 peer_format_bw); 605*71e72c9eSCy Schubert 606*71e72c9eSCy Schubert void (*device_found)(void *ctx, const struct pr_device *dev); 607*71e72c9eSCy Schubert }; 608*71e72c9eSCy Schubert 609*71e72c9eSCy Schubert struct pr_data { 610*71e72c9eSCy Schubert /** 611*71e72c9eSCy Schubert * cfg - PR module configuration 612*71e72c9eSCy Schubert * 613*71e72c9eSCy Schubert * This is included in the same memory allocation with the 614*71e72c9eSCy Schubert * struct pr_data and as such, must not be freed separately. 615*71e72c9eSCy Schubert */ 616*71e72c9eSCy Schubert struct pr_config *cfg; 617*71e72c9eSCy Schubert 618*71e72c9eSCy Schubert struct dl_list devices; 619*71e72c9eSCy Schubert 620*71e72c9eSCy Schubert struct dl_list dev_iks; 621*71e72c9eSCy Schubert 622*71e72c9eSCy Schubert /* PMKSA cache for PASN-PMK authentication */ 623*71e72c9eSCy Schubert struct rsn_pmksa_cache *initiator_pmksa; 624*71e72c9eSCy Schubert struct rsn_pmksa_cache *responder_pmksa; 625*71e72c9eSCy Schubert 626*71e72c9eSCy Schubert /* PR PASN request tracking - similar to pasn_params in wpa_supplicant 627*71e72c9eSCy Schubert */ 628*71e72c9eSCy Schubert struct pr_pasn_ranging_params *pr_pasn_params; 629*71e72c9eSCy Schubert 630*71e72c9eSCy Schubert /* Set when final measurement result received; blocks further results */ 631*71e72c9eSCy Schubert bool ranging_final_received; 632*71e72c9eSCy Schubert }; 633*71e72c9eSCy Schubert 634*71e72c9eSCy Schubert /* PR Device Identity Resolution Attribute parameters */ 635*71e72c9eSCy Schubert struct pr_dira { 636*71e72c9eSCy Schubert /* Cipher version type */ 637*71e72c9eSCy Schubert int cipher_version; 638*71e72c9eSCy Schubert /* Nonce used in DIRA attribute */ 639*71e72c9eSCy Schubert u8 nonce[DEVICE_IDENTITY_NONCE_LEN]; 640*71e72c9eSCy Schubert /* Length of nonce */ 641*71e72c9eSCy Schubert size_t nonce_len; 642*71e72c9eSCy Schubert /* Tag computed for nonce using NIK */ 643*71e72c9eSCy Schubert u8 tag[DEVICE_IDENTITY_TAG_LEN]; 644*71e72c9eSCy Schubert /* Length of tag in octets */ 645*71e72c9eSCy Schubert size_t tag_len; 646*71e72c9eSCy Schubert }; 647*71e72c9eSCy Schubert 648*71e72c9eSCy Schubert struct operation_mode { 649*71e72c9eSCy Schubert /* Bitmap for Ranging Protocol type */ 650*71e72c9eSCy Schubert u8 protocol_type; 651*71e72c9eSCy Schubert 652*71e72c9eSCy Schubert /* Bitmap for Role-ISTA/RSTA */ 653*71e72c9eSCy Schubert u8 role; 654*71e72c9eSCy Schubert 655*71e72c9eSCy Schubert char country[3]; 656*71e72c9eSCy Schubert 657*71e72c9eSCy Schubert struct pr_channels channels; 658*71e72c9eSCy Schubert }; 659*71e72c9eSCy Schubert 660*71e72c9eSCy Schubert struct pr_data * pr_init(const struct pr_config *cfg); 661*71e72c9eSCy Schubert void pr_flush(struct pr_data *pr); 662*71e72c9eSCy Schubert void pr_deinit(struct pr_data *pr); 663*71e72c9eSCy Schubert void pr_set_dev_addr(struct pr_data *pr, const u8 *addr); 664*71e72c9eSCy Schubert void pr_clear_dev_iks(struct pr_data *pr); 665*71e72c9eSCy Schubert void pr_add_dev_ik(struct pr_data *pr, const u8 *dik, const char *password, 666*71e72c9eSCy Schubert const u8 *pmk, size_t pmk_len, bool own); 667*71e72c9eSCy Schubert int pr_set_peer_credentials(struct pr_data *pr, const u8 *addr, 668*71e72c9eSCy Schubert const u8 *pmk, size_t pmk_len, 669*71e72c9eSCy Schubert const char *password); 670*71e72c9eSCy Schubert struct wpabuf * pr_prepare_usd_elems(struct pr_data *pr, const u8 *src_addr); 671*71e72c9eSCy Schubert void pr_process_usd_elems(struct pr_data *pr, const u8 *ies, u16 ies_len, 672*71e72c9eSCy Schubert const u8 *peer_addr, unsigned int freq); 673*71e72c9eSCy Schubert int pr_ensure_oob_peer(struct pr_data *pr, const u8 *addr, int freq); 674*71e72c9eSCy Schubert int pr_initiate_pasn_auth(struct pr_data *pr, const u8 *addr, int freq, 675*71e72c9eSCy Schubert u8 auth_mode, u8 ranging_role, u8 ranging_type, 676*71e72c9eSCy Schubert int forced_pr_freq); 677*71e72c9eSCy Schubert int pr_pasn_auth_tx_status(struct pr_data *pr, const u8 *data, size_t data_len, 678*71e72c9eSCy Schubert bool acked); 679*71e72c9eSCy Schubert int pr_pasn_auth_retransmit(struct pr_data *pr, const u8 *addr); 680*71e72c9eSCy Schubert int pr_pasn_auth_rx(struct pr_data *pr, const struct ieee80211_mgmt *mgmt, 681*71e72c9eSCy Schubert size_t len, int freq); 682*71e72c9eSCy Schubert 683*71e72c9eSCy Schubert #endif /* PROXIMITY_RANGING_H */ 684