1 /* 2 * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: reg_opclass.h 22 * This file provides prototypes of the regulatory opclass functions 23 */ 24 25 #ifndef __REG_OPCLASS_H__ 26 #define __REG_OPCLASS_H__ 27 28 #ifdef CONFIG_AFC_SUPPORT 29 #include <wlan_reg_afc.h> 30 #endif 31 32 #define OPCLS_132 132 33 34 #ifdef HOST_OPCLASS 35 /** 36 * reg_dmn_get_chanwidth_from_opclass() - Get channel width from opclass. 37 * @country: Country code 38 * @channel: Channel number 39 * @opclass: Operating class 40 * 41 * Return: Channel width 42 */ 43 uint16_t reg_dmn_get_chanwidth_from_opclass(uint8_t *country, uint8_t channel, 44 uint8_t opclass); 45 46 /** 47 * reg_dmn_get_opclass_from_channel() - Get operating class from channel. 48 * @country: Country code. 49 * @channel: Channel number. 50 * @offset: Operating class offset. 51 * 52 * Return: Error code. 53 */ 54 uint16_t reg_dmn_get_opclass_from_channel(uint8_t *country, uint8_t channel, 55 uint8_t offset); 56 57 /** 58 * reg_dmn_get_opclass_from_freq_width() - Get operating class from frequency 59 * @country: Country code. 60 * @freq: Channel center frequency. 61 * @ch_width: Channel width. 62 * @behav_limit: Behaviour limit. 63 * 64 * Return: Error code. 65 */ 66 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country, 67 qdf_freq_t freq, 68 uint16_t ch_width, 69 uint16_t behav_limit); 70 71 /** 72 * reg_get_band_cap_from_op_class() - Return band capability bitmap 73 * @country: Pointer to Country code. 74 * @num_of_opclass: Number of Operating class. 75 * @opclass: Pointer to opclass. 76 * 77 * Return supported band bitmap based on the input operating class list 78 * provided. 79 * 80 * Return: Return supported band capability 81 */ 82 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country, 83 uint8_t num_of_opclass, 84 const uint8_t *opclass); 85 86 /** 87 * reg_dmn_get_opclass_from_channe() - Print channels in op class. 88 * @country: Country code. 89 * @opclass: opclass. 90 * 91 * Return: Void. 92 */ 93 void reg_dmn_print_channels_in_opclass(uint8_t *country, uint8_t op_class); 94 95 /** 96 * reg_dmn_set_curr_opclasses() - Set current operating class 97 * @num_classes: Number of classes 98 * @class: Pointer to operating class. 99 * 100 * Return: Error code. 101 */ 102 uint16_t reg_dmn_set_curr_opclasses(uint8_t num_classes, uint8_t *class); 103 104 /** 105 * reg_dmn_get_curr_opclasses() - Get current supported operating classes. 106 * @num_classes: Number of classes. 107 * @class: Pointer to operating class. 108 * 109 * Return: Error code. 110 */ 111 uint16_t reg_dmn_get_curr_opclasses(uint8_t *num_classes, uint8_t *class); 112 113 /** 114 * reg_get_opclass_details() - Get details about the current opclass table. 115 * @pdev: Pointer to pdev. 116 * @reg_ap_cap: Pointer to reg_ap_cap. 117 * @n_opclasses: Pointer to number of opclasses. 118 * @max_supp_op_class: Maximum number of operating classes supported. 119 * @global_tbl_lookup: Whether to lookup global op class table. 120 * 121 * Return: QDF_STATUS_SUCCESS if success, else return QDF_STATUS_FAILURE. 122 */ 123 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev, 124 struct regdmn_ap_cap_opclass_t *reg_ap_cap, 125 uint8_t *n_opclasses, 126 uint8_t max_supp_op_class, 127 bool global_tbl_lookup); 128 129 /** 130 * reg_is_5ghz_op_class() - Check if the input opclass is a 5GHz opclass. 131 * @country: Country code. 132 * @op_class: Operating class. 133 * 134 * Return: Return true if input the opclass is a 5GHz opclass, 135 * else return false. 136 */ 137 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class); 138 139 /** 140 * reg_is_2ghz_op_class() - Check if the input opclass is a 2.4GHz opclass. 141 * @country: Country code. 142 * @op_class: Operating class. 143 * 144 * Return: Return true if input the opclass is a 2.4GHz opclass, 145 * else return false. 146 */ 147 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class); 148 149 #ifdef CONFIG_CHAN_FREQ_API 150 151 /** 152 * reg_freq_width_to_chan_op_class() - convert frequency to oper class, 153 * channel 154 * @pdev: pdev pointer 155 * @freq: channel frequency in mhz 156 * @chan_width: channel width 157 * @global_tbl_lookup: whether to lookup global op class tbl 158 * @behav_limit: behavior limit 159 * @op_class: operating class 160 * @chan_num: channel number 161 * 162 * Return: Void. 163 */ 164 void reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev, 165 qdf_freq_t freq, 166 uint16_t chan_width, 167 bool global_tbl_lookup, 168 uint16_t behav_limit, 169 uint8_t *op_class, 170 uint8_t *chan_num); 171 172 /** 173 * reg_freq_width_to_chan_op_class_auto() - convert frequency to operating 174 * class,channel after fixing up the global_tbl_lookup and behav_limit 175 * for 6G frequencies. 176 * @pdev: pdev pointer 177 * @freq: channel frequency in mhz 178 * @chan_width: channel width 179 * @global_tbl_lookup: whether to lookup global op class tbl 180 * @behav_limit: behavior limit 181 * @op_class: operating class 182 * @chan_num: channel number 183 * 184 * Return: Void. 185 */ 186 void reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev, 187 qdf_freq_t freq, 188 uint16_t chan_width, 189 bool global_tbl_lookup, 190 uint16_t behav_limit, 191 uint8_t *op_class, 192 uint8_t *chan_num); 193 194 /** 195 * reg_freq_to_chan_op_class() - convert frequency to oper class, 196 * channel 197 * @pdev: pdev pointer 198 * @freq: channel frequency in mhz 199 * @global_tbl_lookup: whether to lookup global op class tbl 200 * @behav_limit: behavior limit 201 * @op_class: operating class 202 * @chan_num: channel number 203 * 204 * Return: Void. 205 */ 206 void reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev, 207 qdf_freq_t freq, 208 bool global_tbl_lookup, 209 uint16_t behav_limit, 210 uint8_t *op_class, 211 uint8_t *chan_num); 212 213 /** 214 * reg_is_freq_in_country_opclass() - check for frequency in (tbl, oper class) 215 * 216 * @pdev: pdev pointer 217 * @country: country from country IE 218 * @op_class: operating class 219 * @chan_freq: channel frequency in mhz 220 * 221 * Return: bool 222 */ 223 bool reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev, 224 const uint8_t country[3], 225 uint8_t op_class, 226 qdf_freq_t chan_freq); 227 #endif 228 229 /** 230 * reg_get_op_class_width() - get oper class width 231 * 232 * @pdev: pdev pointer 233 * @global_tbl_lookup: whether to lookup global op class tbl 234 * @op_class: operating class 235 * Return: uint16 236 */ 237 uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev, 238 uint8_t op_class, 239 bool global_tbl_lookup); 240 241 #ifdef HOST_OPCLASS_EXT 242 /** 243 * reg_country_chan_opclass_to_freq() - Convert channel number to frequency 244 * based on country code and op class 245 * @pdev: pdev object. 246 * @country: country code. 247 * @chan: IEEE Channel Number. 248 * @op_class: Opclass. 249 * @strict: flag to find channel from matched operating class code. 250 * 251 * Look up (channel, operating class) pair in country operating class tables 252 * and return the channel frequency. 253 * If not found and "strict" flag is false, try to get frequency (Mhz) by 254 * channel number only. 255 * 256 * Return: Channel center frequency else return 0. 257 */ 258 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev, 259 const uint8_t country[3], 260 uint8_t chan, uint8_t op_class, 261 bool strict); 262 #endif 263 264 /** 265 * reg_chan_opclass_to_freq() - Convert channel number and opclass to frequency 266 * @chan: IEEE Channel Number. 267 * @op_class: Opclass. 268 * @global_tbl_lookup: Global table lookup. 269 * 270 * Return: Channel center frequency else return 0. 271 */ 272 uint16_t reg_chan_opclass_to_freq(uint8_t chan, 273 uint8_t op_class, 274 bool global_tbl_lookup); 275 276 /** 277 * reg_chan_opclass_to_freq_auto() - Convert channel number and opclass to 278 * frequency after fixing global_tbl_lookup 279 * @chan: IEEE Channel Number. 280 * @op_class: Opclass. 281 * @global_tbl_lookup: Global table lookup. 282 * 283 * Return: Channel center frequency else return 0. 284 */ 285 qdf_freq_t reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class, 286 bool global_tbl_lookup); 287 288 #else 289 290 static inline uint16_t reg_dmn_get_chanwidth_from_opclass( 291 uint8_t *country, uint8_t channel, uint8_t opclass) 292 { 293 return 0; 294 } 295 296 static inline uint16_t reg_dmn_set_curr_opclasses( 297 uint8_t num_classes, uint8_t *class) 298 { 299 return 0; 300 } 301 302 static inline uint16_t reg_dmn_get_curr_opclasses( 303 uint8_t *num_classes, uint8_t *class) 304 { 305 return 0; 306 } 307 308 static inline uint16_t reg_dmn_get_opclass_from_channel( 309 uint8_t *country, uint8_t channel, uint8_t offset) 310 { 311 return 0; 312 } 313 314 static inline 315 uint8_t reg_dmn_get_opclass_from_freq_width(uint8_t *country, 316 qdf_freq_t freq, 317 uint16_t ch_width, 318 uint16_t behav_limit) 319 { 320 return 0; 321 } 322 323 static inline 324 uint8_t reg_get_band_cap_from_op_class(const uint8_t *country, 325 uint8_t num_of_opclass, 326 const uint8_t *opclass) 327 { 328 return 0; 329 } 330 331 static inline void reg_dmn_print_channels_in_opclass(uint8_t *country, 332 uint8_t op_class) 333 { 334 } 335 336 static inline 337 QDF_STATUS reg_get_opclass_details(struct wlan_objmgr_pdev *pdev, 338 struct regdmn_ap_cap_opclass_t *reg_ap_cap, 339 uint8_t *n_opclasses, 340 uint8_t max_supp_op_class, 341 bool global_tbl_lookup) 342 { 343 return QDF_STATUS_E_FAILURE; 344 } 345 346 static inline 347 bool reg_is_5ghz_op_class(const uint8_t *country, uint8_t op_class) 348 { 349 return false; 350 } 351 352 static inline 353 bool reg_is_2ghz_op_class(const uint8_t *country, uint8_t op_class) 354 { 355 return false; 356 } 357 358 #ifdef CONFIG_CHAN_FREQ_API 359 360 static inline void 361 reg_freq_width_to_chan_op_class(struct wlan_objmgr_pdev *pdev, 362 qdf_freq_t freq, 363 uint16_t chan_width, 364 bool global_tbl_lookup, 365 uint16_t behav_limit, 366 uint8_t *op_class, 367 uint8_t *chan_num) 368 { 369 } 370 371 static inline void 372 reg_freq_width_to_chan_op_class_auto(struct wlan_objmgr_pdev *pdev, 373 qdf_freq_t freq, 374 uint16_t chan_width, 375 bool global_tbl_lookup, 376 uint16_t behav_limit, 377 uint8_t *op_class, 378 uint8_t *chan_num) 379 { 380 } 381 382 static inline void 383 reg_freq_to_chan_op_class(struct wlan_objmgr_pdev *pdev, 384 qdf_freq_t freq, 385 bool global_tbl_lookup, 386 uint16_t behav_limit, 387 uint8_t *op_class, 388 uint8_t *chan_num) 389 { 390 } 391 392 static inline bool 393 reg_is_freq_in_country_opclass(struct wlan_objmgr_pdev *pdev, 394 const uint8_t country[3], 395 uint8_t op_class, 396 uint16_t chan_freq) 397 { 398 return false; 399 } 400 401 #endif 402 403 static inline uint16_t reg_get_op_class_width(struct wlan_objmgr_pdev *pdev, 404 uint8_t op_class, 405 bool global_tbl_lookup) 406 { 407 return 0; 408 } 409 410 #ifdef HOST_OPCLASS_EXT 411 static inline 412 qdf_freq_t reg_country_chan_opclass_to_freq(struct wlan_objmgr_pdev *pdev, 413 const uint8_t country[3], 414 uint8_t chan, uint8_t op_class, 415 bool strict) 416 { 417 return 0; 418 } 419 #endif 420 421 static inline uint16_t 422 reg_chan_opclass_to_freq(uint8_t chan, 423 uint8_t op_class, 424 bool global_tbl_lookup) 425 { 426 return 0; 427 } 428 429 static inline qdf_freq_t 430 reg_chan_opclass_to_freq_auto(uint8_t chan, uint8_t op_class, 431 bool global_tbl_lookup) 432 { 433 return 0; 434 } 435 #endif 436 437 /** 438 * reg_dmn_get_chanwidth_from_opclass_auto()- Get channel width for the 439 * given channel and opclass. If not found then search it in the global 440 * op class. 441 * @country - Country 442 * @channel - Channel for which channel spacing is required 443 * @opclass - Opclass to search from. 444 * 445 * Return: valid channel spacing if found. If not found then 446 * return 0. 447 */ 448 uint16_t reg_dmn_get_chanwidth_from_opclass_auto(uint8_t *country, 449 uint8_t channel, 450 uint8_t opclass); 451 452 #ifdef CONFIG_AFC_SUPPORT 453 454 /** 455 * reg_dmn_get_6g_opclasses_and_channels()- Get the following from the 456 * operating class table for 6Ghz band: number of operating classes, list of 457 * opclasses, list channel sizes, list of channel lists. 458 * @p_frange_lst: Pointer to frequencey range list (AFC) 459 * @pdev: Pointer to pdev. 460 * @num_opclasses: Pointer to number of operating classes. This is the number 461 * of elements in the list array arguments 462 * @opclas_lst: Pointer to pointer to memory of list of opclasses 463 * @chansize_lst: Pointer to pointer to memory of list of channel sizes 464 * @channel_lists: Array of pointers to pointer to memory of list of channels 465 * 466 * Return: QDF_STATUS 467 * NOTE:- All memory allocations done by this function should be freed by the 468 * caller. The caller may use the function 469 * 'reg_dmn_free_6g_opclasses_and_channels' to free the allocations. 470 */ 471 472 QDF_STATUS reg_dmn_get_6g_opclasses_and_channels(struct wlan_objmgr_pdev *pdev, 473 struct wlan_afc_frange_list *p_frange_lst, 474 uint8_t *num_opclasses, 475 uint8_t **opclass_lst, 476 uint8_t **chansize_lst, 477 uint8_t **channel_lists[]); 478 479 /** 480 * reg_dmn_free_6g_opclasses_and_channels()- Free the memory allocated by 481 * the pointers and arrays indicated by the arguments. 482 * @pdev: Pointer to pdev. 483 * @num_opclasses: Number of operating classes. This is the number of 484 * elements in the 'channel_lists' array. 485 * @opclas_lst: Pointer to memory of list of opclasses 486 * @chansize_lst: Pointer to memory of list of channel sizes 487 * @channel_lists: Array of pointers to memory of list of channels 488 * 489 * Return: void 490 */ 491 void reg_dmn_free_6g_opclasses_and_channels(struct wlan_objmgr_pdev *pdev, 492 uint8_t num_opclasses, 493 uint8_t *opclass_lst, 494 uint8_t *chansize_lst, 495 uint8_t *channel_lists[]); 496 #endif 497 #endif 498