|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** @file |
| 8 | + * @brief nRF70 Bare Metal library. |
| 9 | + * @defgroup nrf70_bm nRF70 Bare Metal library |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef NRF70_BM_H__ |
| 13 | +#define NRF70_BM_H__ |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | + |
| 19 | +#include <stdint.h> |
| 20 | +#include <stdbool.h> |
| 21 | +#include <stdio.h> |
| 22 | + |
| 23 | +/** @brief Log levels */ |
| 24 | +#if CONFIG_NRF70_BM_LOG_LEVEL > 0 |
| 25 | +#define NRF70_LOG_ERR(...) printf(__VA_ARGS__); printf("\n") |
| 26 | +#else |
| 27 | +#define NRF70_LOG_ERR(...) |
| 28 | +#endif |
| 29 | + |
| 30 | +#if CONFIG_NRF70_BM_LOG_LEVEL > 1 |
| 31 | +#define NRF70_LOG_WRN(...) printf(__VA_ARGS__); printf("\n") |
| 32 | +#else |
| 33 | +#define NRF70_LOG_WRN(...) |
| 34 | +#endif |
| 35 | + |
| 36 | +#if CONFIG_NRF70_BM_LOG_LEVEL > 2 |
| 37 | +#define NRF70_LOG_INF(...) printf(__VA_ARGS__); printf("\n") |
| 38 | +#else |
| 39 | +#define NRF70_LOG_INF(...) |
| 40 | +#endif |
| 41 | + |
| 42 | +#if CONFIG_NRF70_BM_LOG_LEVEL > 3 |
| 43 | +#define NRF70_LOG_DBG(...) printf(__VA_ARGS__); printf("\n") |
| 44 | +#else |
| 45 | +#define NRF70_LOG_DBG(...) |
| 46 | +#endif |
| 47 | + |
| 48 | + |
| 49 | +#define NR70_SCAN_SSID_MAX_LEN 32 |
| 50 | +#ifdef CONFIG_NRF70_SCAN_SSID_FILT_MAX |
| 51 | +#define NRF70_SCAN_SSID_FILT_MAX CONFIG_NRF70_SCAN_SSID_FILT_MAX |
| 52 | +#else |
| 53 | +#define NRF70_SCAN_SSID_FILT_MAX 1 |
| 54 | +#endif /* CONFIG_NRF70_SCAN_SSID_FILT_MAX */ |
| 55 | + |
| 56 | +#ifdef CONFIG_NRF70_SCAN_CHAN_MAX_MANUAL |
| 57 | +#define NRF70_SCAN_CHAN_MAX_MANUAL CONFIG_NRF70_SCAN_CHAN_MAX_MANUAL |
| 58 | +#else |
| 59 | +#define NRF70_SCAN_CHAN_MAX_MANUAL 1 |
| 60 | +#endif /* CONFIG_NRF70_SCAN_CHAN_MAX_MANUAL */ |
| 61 | + |
| 62 | +/** @brief Wi-Fi version */ |
| 63 | +struct wifi_version { |
| 64 | + /** Driver version */ |
| 65 | + const char *drv_version; |
| 66 | + /** Firmware version */ |
| 67 | + const char *fw_version; |
| 68 | +}; |
| 69 | + |
| 70 | +/** @brief Wi-Fi scanning types. */ |
| 71 | +enum nrf70_scan_type { |
| 72 | + /** Active scanning (default). */ |
| 73 | + WIFI_SCAN_TYPE_ACTIVE = 0, |
| 74 | + /** Passive scanning. */ |
| 75 | + WIFI_SCAN_TYPE_PASSIVE, |
| 76 | +}; |
| 77 | + |
| 78 | +/** |
| 79 | + * @brief Wi-Fi structure to uniquely identify a band-channel pair |
| 80 | + */ |
| 81 | +struct wifi_band_channel { |
| 82 | + /** Frequency band */ |
| 83 | + uint8_t band; |
| 84 | + /** Channel */ |
| 85 | + uint8_t channel; |
| 86 | +}; |
| 87 | + |
| 88 | +/** |
| 89 | + * @brief Wi-Fi scan parameters structure. |
| 90 | + * Used to specify parameters which can control how the Wi-Fi scan |
| 91 | + * is performed. |
| 92 | + */ |
| 93 | +struct nrf70_scan_params { |
| 94 | + /** Scan type, see enum wifi_scan_type. |
| 95 | + * |
| 96 | + * The scan_type is only a hint to the underlying Wi-Fi chip for the |
| 97 | + * preferred mode of scan. The actual mode of scan can depend on factors |
| 98 | + * such as the Wi-Fi chip implementation support, regulatory domain |
| 99 | + * restrictions etc. |
| 100 | + */ |
| 101 | + enum nrf70_scan_type scan_type; |
| 102 | + /** Bitmap of bands to be scanned. |
| 103 | + * Refer to ::wifi_frequency_bands for bit position of each band. |
| 104 | + */ |
| 105 | + uint8_t bands; |
| 106 | + /** Active scan dwell time (in ms) on a channel. |
| 107 | + */ |
| 108 | + uint16_t dwell_time_active; |
| 109 | + /** Passive scan dwell time (in ms) on a channel. |
| 110 | + */ |
| 111 | + uint16_t dwell_time_passive; |
| 112 | + /** Array of SSID strings to scan. |
| 113 | + */ |
| 114 | + const char *ssids[NRF70_SCAN_SSID_FILT_MAX]; |
| 115 | + /** Specifies the maximum number of scan results to return. These results would be the |
| 116 | + * BSSIDS with the best RSSI values, in all the scanned channels. This should only be |
| 117 | + * used to limit the number of returned scan results, and cannot be counted upon to limit |
| 118 | + * the scan time, since the underlying Wi-Fi chip might have to scan all the channels to |
| 119 | + * find the max_bss_cnt number of APs with the best signal strengths. A value of 0 |
| 120 | + * signifies that there is no restriction on the number of scan results to be returned. |
| 121 | + */ |
| 122 | + uint16_t max_bss_cnt; |
| 123 | + /** Channel information array indexed on Wi-Fi frequency bands and channels within that |
| 124 | + * band. |
| 125 | + * E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band: |
| 126 | + * @code{.c} |
| 127 | + * chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6}; |
| 128 | + * chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11}; |
| 129 | + * chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36}; |
| 130 | + * @endcode |
| 131 | + * |
| 132 | + * This list specifies the channels to be __considered for scan__. The underlying |
| 133 | + * Wi-Fi chip can silently omit some channels due to various reasons such as channels |
| 134 | + * not conforming to regulatory restrictions etc. The invoker of the API should |
| 135 | + * ensure that the channels specified follow regulatory rules. |
| 136 | + */ |
| 137 | + struct wifi_band_channel band_chan[NRF70_SCAN_CHAN_MAX_MANUAL]; |
| 138 | +}; |
| 139 | + |
| 140 | +/**@brief Initialize the WiFi module. |
| 141 | + * |
| 142 | + * @retval 0 If the operation was successful. |
| 143 | + * @retval -1 If the operation failed. |
| 144 | + */ |
| 145 | +int nrf70_init(void); |
| 146 | + |
| 147 | +/**@brief Start scanning for WiFi networks. |
| 148 | + * |
| 149 | + * @param[in] scan_params Scan parameters. |
| 150 | + * |
| 151 | + * @retval 0 If the operation was successful. |
| 152 | + * @retval -EINVAL If the scan parameters are invalid. |
| 153 | + * @retval -EBUSY If the scan is already in progress. |
| 154 | + * @retval -EIO If the operation failed. |
| 155 | + * @retval -ENOMEM If there is not enough memory to start the scan. |
| 156 | + */ |
| 157 | +int nrf70_scan_start(struct nrf70_scan_params *scan_params); |
| 158 | + |
| 159 | +/**@brief Check if the WiFi scan is done. |
| 160 | + * |
| 161 | + * @retval 0 If the scan is not done. |
| 162 | + * @retval 1 If the scan is done. |
| 163 | + */ |
| 164 | +bool nrf70_scan_done(void); |
| 165 | + |
| 166 | +/**@brief Print the WiFi scan results. |
| 167 | + */ |
| 168 | +void nrf70_scan_print_results(void); |
| 169 | + |
| 170 | +/**@brief Clean up the WiFi module. |
| 171 | + */ |
| 172 | +int nrf70_deinit(void); |
| 173 | + |
| 174 | +#ifdef __cplusplus |
| 175 | +} |
| 176 | +#endif |
| 177 | + |
| 178 | +#endif /* NRF70_BM_H__ */ |
0 commit comments