1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_PAL_WIFI_PAL_CONVERT_H_ 18 #define CHRE_PAL_WIFI_PAL_CONVERT_H_ 19 20 /** 21 * @file 22 * Defines helper functions to convert data into CHRE-defined structures. 23 * 24 * These functions can be used by the CHRE WiFi PAL implementation to help 25 * convert WLAN data to CHRE-defined structures so they can be delivered through 26 * the PAL interface. 27 */ 28 29 #include <inttypes.h> 30 #include <stdbool.h> 31 #include <stdint.h> 32 33 #include "chre_api/chre/wifi.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 // The bit-level definitions of the LCI subelement data specified by the 40 // IEEE P802.11-REVmc/D8.0. 41 // | Element name (number of bytes) | 42 // ------------------------------------------------------------- 43 // | Subelement ID (1) | Subelement length (1) | 44 // | Subelement (variable) 45 #define CHRE_LCI_SUBELEMENT_HEADER_LEN_BYTES 2 46 47 // 48 // If the subelement length is non-zero, it must be 16, and the LCI subelement 49 // is represented by the following: 50 // | Element name (number of bits) | 51 // ------------------------------------------------------------- 52 // | Latitude uncertainty (6) | Latitude (34) 53 // | Longitude uncertainty (6) | Longitude (34) 54 // | Altitude type (4) | Altitude uncertainty (6) 55 // | Altitude (30) | Datum (3) | RegLog Agreement (1) 56 // | RegLog DSE (1) | Dependent STA (1) 57 // | Version (2) 58 #define CHRE_LCI_SUBELEMENT_DATA_LEN_BYTES 16 59 60 // The LCI IE header data, as defined by figure IEEE P802.11-REVmc/D8.0 61 // spec section 9.4.2.22. This header precedes the LCI subelement data defined 62 // above. 63 // | Element name (number of bytes) | 64 // ------------------------------------------------------------- 65 // | Measurement token (1) | Measurement report mode (1) 66 // | Measurement type (1) | Measurement (variable) 67 #define CHRE_LCI_IE_HEADER_LEN_BYTES 3 68 69 /** 70 * Converts LCI IE data specified by IEEE P802.11-REVmc/D8.0 spec section 71 * 9.4.2.22, under Measurement Report Element. 72 * 73 * The input is assumed to point to the beginning of the LCI IE data, which 74 * includes the header defined above. 75 * 76 * If the input is valid, this function will return true and will store 77 * flags and lci fields in the supplied chreWifiRangingResult input. 78 * 79 * @param ieData The LCI IE data array. 80 * @param len The length of ieData in bytes. 81 * @param out A non-null pointer to store the conversion result. 82 * 83 * @return true if the conversion succeeded, and false if the input was 84 * malformed. 85 */ 86 bool chreWifiLciFromIe(const uint8_t *ieData, size_t len, 87 struct chreWifiRangingResult *out); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif // CHRE_PAL_WIFI_PAL_CONVERT_H_ 94