hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/******************************************************************************
 *
 * Copyright(c) 2020 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#ifndef _PHL_REGULATION_DEF_H_
#define _PHL_REGULATION_DEF_H_
 
#define PHL_GET_CHPLAN_UPDATE_INFO_2G(_did_, _info_, \
   _dm_tbl_, _chdef_tbl_) \
do { \
   u8 size = sizeof((_chdef_tbl_)) / sizeof(struct chdef_2ghz); \
   regu_get_chplan_update_result_2g((_did_), size, (_info_),\
       &(_dm_tbl_)[0], &(_chdef_tbl_)[0]); \
} while (0)
 
#define PHL_GET_CHPLAN_UPDATE_INFO_5G(_group_, _did_, _info_, \
   _dm_tbl_, _chdef_tbl_) \
do { \
   u8 size = sizeof((_chdef_tbl_)) / sizeof(struct chdef_5ghz); \
   regu_get_chplan_update_result_5g((_group_), (_did_), size, (_info_),\
       &(_dm_tbl_)[0], &(_chdef_tbl_)[0]); \
} while (0)
 
#define PHL_GET_DOMAIN_INDEX(_idx_, _domain_, _dm_tbl_) \
do { \
   u8 i, size; \
   (_idx_) = INVALID_DOMAIN_INDEX; \
   size = sizeof((_dm_tbl_)) / sizeof(struct regulatory_domain_mapping); \
   for (i = 0; i < size; i++) { \
       if ((_domain_) == (_dm_tbl_)[i].domain_code) { \
           (_idx_) = i; \
           break; \
       } \
   } \
} while (0)
 
#define PHL_GET_DOMAIN_REGU(_regu_, _domain_, _dm_tbl_, _band_) \
do { \
   u8 did = INVALID_DOMAIN_INDEX; \
   (_regu_) = REGULATION_MAX; \
   PHL_GET_DOMAIN_INDEX(did, (_domain_), (_dm_tbl_)); \
   if (did == INVALID_DOMAIN_INDEX) \
       break; \
   switch ((_band_)) { \
   case BAND_ON_24G: \
       (_regu_) = (_dm_tbl_)[did].freq_2g.regulation; \
       break; \
   case BAND_ON_5G: \
       (_regu_) = (_dm_tbl_)[did].freq_5g.regulation; \
       break; \
   case BAND_ON_6G: \
   case BAND_MAX: \
       break; \
   } \
} while (0)
 
#define PHL_GET_CNTRY_INDEX(_cntry_, _idx_, _cntry_tbl_) \
do { \
   u8 i; \
   u8 size = sizeof((_cntry_tbl_)) / sizeof(struct country_domain_mapping); \
   (_idx_) = INVALID_CNTRY_IDX; \
   for (i = 0; i < size; i++) { \
       if ((_cntry_tbl_)[i].char2[0] == (_cntry_)[0] && \
           (_cntry_tbl_)[i].char2[1] == (_cntry_)[1]) { \
           (_idx_) = i; \
           break; \
       } \
   } \
} while (0)
 
#define PHL_GET_CNTRY_TBL_SIZE(_size_, _cntry_tbl_) \
   (_size_) = sizeof((_cntry_tbl_)) / sizeof(struct country_domain_mapping);
 
#define PHL_QRY_GRP_CNTRY_NUM(_num_, _policy_, _id_, _dm_tbl_, _cntry_tbl_) \
do { \
   u8 dm_size = sizeof((_dm_tbl_)) / sizeof(struct regulatory_domain_mapping); \
   u8 cntry_size = sizeof((_cntry_tbl_)) / sizeof(struct country_domain_mapping); \
   (_num_) = 0; \
   (_num_) = regu_calculate_group_cntry_num( \
       (_policy_), (_id_), dm_size, cntry_size, &(_dm_tbl_)[0], &(_cntry_tbl_)[0]); \
} while (0)
 
 
#define PHL_FILL_GRP_CNTRY_LIST(_policy_, _list_, _len_, _id_, _dm_tbl_, _cntry_tbl_) \
do { \
   u8 dm_size = sizeof((_dm_tbl_)) / sizeof(struct regulatory_domain_mapping); \
   u8 cntry_size = sizeof((_cntry_tbl_)) / sizeof(struct country_domain_mapping); \
   if (!(_policy_) || !(_list_)) \
       break; \
   regu_fill_specific_group_cntry_list( \
       (_policy_), (_list_), (_len_), (_id_), dm_size, \
       cntry_size, &(_dm_tbl_)[0], &(_cntry_tbl_)[0]); \
} while (0) \
 
#define PHL_QRY_CNTRY_CHNLPLAN(_cntry_, _chnlplan_, _cntry_tbl_) \
do { \
   u8 size = sizeof((_cntry_tbl_)) / sizeof(struct country_domain_mapping); \
   regu_fill_chnlplan_content((_cntry_), size, (_chnlplan_), &(_cntry_tbl_)[0]); \
} while (0)
 
/* 6g */
#define PHL_GET_CHDEF_6G(_idx_, _chdef_, _chdef_tbl_) \
do { \
   u8 size = sizeof(_chdef_tbl_) / sizeof(struct chdef_6ghz); \
   regu_get_chdef_6g((_idx_), size, (_chdef_), &(_chdef_tbl_)[0]); \
} while (0)
 
#define PHL_GET_DOMAIN_INDEX_6G(_idx_, _domain_, _dm_tbl_) \
do { \
   u8 i, size; \
   (_idx_) = INVALID_DOMAIN_INDEX; \
   size = sizeof((_dm_tbl_)) / sizeof(struct regulatory_domain_mapping_6g); \
   for (i = 0; i < size; i++) { \
       if ((_domain_) == (_dm_tbl_)[i].domain_code) { \
           (_idx_) = i; \
           break; \
       } \
   } \
} while (0)
 
#define PHL_GET_6G_REGULATORY_INFO(_code_, _regu_, \
   _ch_idx_, _domain_, _dm_tbl_) \
do { \
   u8 idx = INVALID_DOMAIN_INDEX; \
   PHL_GET_DOMAIN_INDEX_6G(idx, (_domain_), (_dm_tbl_)); \
   if (idx != INVALID_DOMAIN_INDEX) { \
       (_code_) = (_dm_tbl_)[idx].domain_code; \
       (_regu_) = (_dm_tbl_)[idx].regulation; \
       (_ch_idx_) = (_dm_tbl_)[idx].ch_idx; \
   } \
} while (0)
 
#define PHL_GET_CAT6G_BY_COUNTRY(_cat_6g_, _cntry_, _cntry_tbl_) \
do { \
   u8 idx = INVALID_CNTRY_IDX; \
   PHL_GET_CNTRY_INDEX((_cntry_), idx, (_cntry_tbl_)); \
   if (INVALID_CNTRY_IDX == idx) {\
       (_cat_6g_) = 0; \
       break; \
   } \
   (_cat_6g_) = (_cntry_tbl_)[idx].category_6g; \
} while (0)
 
#define INVALID_DOMAIN_CODE 0xff
#define INVALID_CH_IDX 0xff
#define INVALID_REGU_NUM 0xff
#define INVALID_CNTRY_IDX 0xff
#define INVALID_VER 0x0
#define INVALID_GROUP 0xff
 
#define RSVD_DOMAIN 0x1a
 
#define MAX_CH_NUM_2GHZ 14
 
#define MAX_CH_NUM_BAND1 4 /* 36, 40, 44, 48 */
#define MAX_CH_NUM_BAND2 4 /* 52, 56, 60, 64 */
#define MAX_CH_NUM_BAND3 12 /* 100, 104, 108, 112,
               116, 120, 124, 128,
               132, 136, 140, 144 */
#define MAX_CH_NUM_BAND4 8 /* 149, 153, 157, 161, 165, 169, 173, 177 */
#define MAX_CH_NUM_5GHZ (MAX_CH_NUM_BAND1 + MAX_CH_NUM_BAND2 +\
               MAX_CH_NUM_BAND3 + MAX_CH_NUM_BAND4)
 
#define MAX_CH_NUM_UNII5 24 /* 1 ~ 93 */
#define MAX_CH_NUM_UNII6 6 /* 97 ~ 117 */
#define MAX_CH_NUM_UNII7 18 /* 121 ~ 189 */
#define MAX_CH_NUM_UNII8 11 /* 193 ~ 233 */
#define MAX_CH_NUM_6GHZ (MAX_CH_NUM_UNII5 + MAX_CH_NUM_UNII6 +\
               MAX_CH_NUM_UNII7 + MAX_CH_NUM_UNII8)
 
 
#define BAND_2GHZ(_band_) ((_band_ == BAND_ON_24G) ? true : false)
#define BAND_5GHZ(_band_) ((_band_ == BAND_ON_5G) ? true : false)
#define BAND_6GHZ(_band_) ((_band_ == BAND_ON_6G) ? true : false)
 
#define CH_2GHZ(_ch_) (((_ch_ >= 1) && (_ch_ <= 14)) ? true : false)
#define CH_5GHZ_BAND1(_ch_) (((_ch_ >= 36) && (_ch_ <= 48)) ? true : false)
#define CH_5GHZ_BAND2(_ch_) (((_ch_ >= 52) && (_ch_ <= 64)) ? true : false)
#define CH_5GHZ_BAND3(_ch_) (((_ch_ >= 100) && (_ch_ <= 144)) ? true : false)
#define CH_5GHZ_BAND4(_ch_) (((_ch_ >= 149) && (_ch_ <= 177)) ? true : false)
#define CH_59GHZ(_ch_) (((_ch_ > 165) && (_ch_ <= 177)) ? true : false)
 
/* UNII-5 support channel list, ch1 ~ ch93, total : 24 */
/* UNII-6 support channel list, ch97 ~ ch117, total : 6 */
/* UNII-7 support channel list, ch121 ~ ch189, total : 18 */
/* UNII-8 support channel list, ch193 ~ ch233, total : 11 */
#define CH_6GHZ_UNII5(_ch_) (((_ch_ >= 1) && (_ch_ <= 93)) ? true : false)
#define CH_6GHZ_UNII6(_ch_) (((_ch_ >= 97) && (_ch_ <= 117)) ? true : false)
#define CH_6GHZ_UNII7(_ch_) (((_ch_ >= 121) && (_ch_ <= 189)) ? true : false)
#define CH_6GHZ_UNII8(_ch_) (((_ch_ >= 193) && (_ch_ <= 233)) ? true : false)
 
#define CH_IN_SAME_5G_BAND(ch_a, ch_b) \
   ((CH_5GHZ_BAND4(ch_a) && CH_5GHZ_BAND4(ch_b)) \
   || (CH_5GHZ_BAND3(ch_a) && CH_5GHZ_BAND3(ch_b)) \
   || (CH_5GHZ_BAND2(ch_a) && CH_5GHZ_BAND2(ch_b)) \
   || (CH_5GHZ_BAND1(ch_a) && CH_5GHZ_BAND1(ch_b)))
 
#define CH_IN_SAME_6G_BAND(ch_a, ch_b) \
   ((CH_6GHZ_UNII8(ch_a) && CH_6GHZ_UNII8(ch_b)) \
   || (CH_6GHZ_UNII7(ch_a) && CH_6GHZ_UNII7(ch_b)) \
   || (CH_6GHZ_UNII6(ch_a) && CH_6GHZ_UNII6(ch_b)) \
   || (CH_6GHZ_UNII5(ch_a) && CH_6GHZ_UNII5(ch_b)))
 
#define SUPPORT_11A BIT(0)
#define SUPPORT_11B BIT(1)
#define SUPPORT_11G BIT(2)
#define SUPPORT_11N BIT(3)
#define SUPPORT_11AC BIT(4)
#define SUPPORT_11AX BIT(5)
 
#define INVALID_DOMAIN_INDEX 0xff
#define MAX_CNTRY_NUM 0xff
 
enum regulation_rsn {
   REGU_RSN_DEFAULT = 0x0,
   REGU_RSN_SMBIOS,
   REGU_RSN_EFUSE,
   REGU_RSN_11D,
   REGU_RSN_REGISTRY,
   REGU_RSN_LOCATION,
   REGU_RSN_MANUAL,
   REGU_RSN_CUSTOM,
   REGU_RSN_MAX
};
 
enum rtw_regulation_capability {
   CAPABILITY_2GHZ = BIT(0),
   CAPABILITY_5GHZ = BIT(1),
   CAPABILITY_DFS = BIT(2),
   CAPABILITY_6GHZ = BIT(3),
   CAPABILITY_59GHZ = BIT(4),
};
 
enum rtw_regulation_query {
   REGULQ_CHPLAN_2GHZ = BIT(0),
   REGULQ_CHPLAN_5GHZ_BAND1 = BIT(1),
   REGULQ_CHPLAN_5GHZ_BAND2 = BIT(2),
   REGULQ_CHPLAN_5GHZ_BAND3 = BIT(3),
   REGULQ_CHPLAN_5GHZ_BAND4 = BIT(4),
   REGULQ_CHPLAN_6GHZ_UNII5 = BIT(5),
   REGULQ_CHPLAN_6GHZ_UNII6 = BIT(6),
   REGULQ_CHPLAN_6GHZ_UNII7 = BIT(7),
   REGULQ_CHPLAN_6GHZ_UNII8 = BIT(8),
   REGULQ_CHPLAN_6GHZ_PSC = BIT(9),
   REGULQ_CHPLAN_6GHZ_ALL = (REGULQ_CHPLAN_6GHZ_UNII5 |
       REGULQ_CHPLAN_6GHZ_UNII6 | REGULQ_CHPLAN_6GHZ_UNII7 |
       REGULQ_CHPLAN_6GHZ_UNII8),
   REGULQ_CHPLAN_5GHZ_ALL = (REGULQ_CHPLAN_5GHZ_BAND1 |
       REGULQ_CHPLAN_5GHZ_BAND2 | REGULQ_CHPLAN_5GHZ_BAND3 |
       REGULQ_CHPLAN_5GHZ_BAND4),
   REGULQ_CHPLAN_2GHZ_5GHZ = (REGULQ_CHPLAN_2GHZ |
       REGULQ_CHPLAN_5GHZ_BAND1 | REGULQ_CHPLAN_5GHZ_BAND2 |
       REGULQ_CHPLAN_5GHZ_BAND3 | REGULQ_CHPLAN_5GHZ_BAND4),
   REGULQ_CHPLAN_FULL = (REGULQ_CHPLAN_2GHZ | REGULQ_CHPLAN_5GHZ_ALL |
                   REGULQ_CHPLAN_6GHZ_ALL),
   REGULQ_CHPLAN_DEF = (REGULQ_CHPLAN_2GHZ | REGULQ_CHPLAN_5GHZ_ALL |
                   REGULQ_CHPLAN_6GHZ_PSC),
};
 
enum country_property {
   CNTRY_EU = BIT(0), /* European Union */
};
 
enum ch_property {
   CH_PASSIVE = BIT(0), /* regulatory passive channel */
   CH_DFS = BIT(1), /* 5 ghz DFS channel */
   CH_PSC = BIT(2) /* 6 ghz preferred scanning channel */
};
 
enum rtw_regulation_group_id {
   DEFAULT_SUPPORT_6G = 0x0,
   CURRENT_SUPPORT_6G,
   EU_GROUP,
   FCC_GROUP,
   OTHERS_MODULE_RF_APPROVAL
};
 
struct rtw_regulation_channel {
   enum band_type band;
   u8 channel;
   u8 property;
};
 
struct rtw_regulation_chplan {
   u32 cnt;
   struct rtw_regulation_channel ch[MAX_CH_NUM_2GHZ +
                   MAX_CH_NUM_5GHZ +
                   MAX_CH_NUM_6GHZ];
};
 
struct rtw_ch {
   enum band_type band;
   u8 ch;
};
 
struct rtw_chlist {
   u32 cnt;
   struct rtw_ch ch[MAX_CH_NUM_2GHZ +
           MAX_CH_NUM_5GHZ +
           MAX_CH_NUM_6GHZ];
};
 
struct rtw_regulatory_domain {
   u8 domain; /* original 2/5 ghz domain */
   u8 domain_6g; /* 6 ghz domain */
};
 
enum cntry_property_6g_bp {
   CP_6G_BAND_BLOCKED = BIT(0), /* country is blocked, cannot use 6 ghz band */
   CP_6G_BAND_SOFTAP_BLOCKED = BIT(1), /* country cannot use softap on 6 ghz band */
};
 
enum cntry_property_5g_bp {
   CP_5G_BAND1_SOFTAP_BLOCKED = BIT(0), /* country cannot use softap on 5 ghz band 1 */
   CP_5G_BAND2_SOFTAP_BLOCKED = BIT(1), /* country cannot use softap on 5 ghz band 2 */
   CP_5G_BAND3_SOFTAP_BLOCKED = BIT(2), /* country cannot use softap on 5 ghz band 3 */
   CP_5G_BAND4_SOFTAP_BLOCKED = BIT(3), /* country cannot use softap on 5 ghz band 4 */
};
 
enum cp_bp_mode { /* country property - band policy mode */
   BLOCK_MODE = 0, /* selected countries are blocked, otherwise follow RTK */
   ALLOW_MODE = 1, /* selected countries are allowed (to follow RTK), otherwise blocked */
};
 
enum rtw_power_limit_6g_info {
   PWR_LMT_6G_LPI = 0,
   PWR_LMT_6G_STD,
   PWR_LMT_6G_VLP,
   PWR_LMT_6G_MAX,
};
 
struct rtw_regu_policy_info {
   u8 valid_6g_bp;
   u8 cp_6g_bp; /* country property - 6g band policy */
   u8 valid_5g_bp;
   u8 cp_5g_bp; /* country property - 5g band policy */
};
 
struct rtw_regulation_info {
   u8 domain_code;
   u8 domain_reason;
   u8 domain_code_6g;
   u8 domain_reason_6g;
   char country[2];
   u8 support_mode;
   u8 regulation_2g;
   u8 regulation_5g;
   u8 regulation_6g;
   enum rtw_power_limit_6g_info category_6g;
   u8 tpo;
   u8 chplan_ver;
   u8 country_ver;
   u16 capability;
 
   /* Regulation table source:
    * 0 for common tbl
    * 1 for IC module tbl
    * >= 2 for customized tbl
    */
   u8 tbl_idx;
};
 
struct rtw_regulation_interface {
   _os_lock lock;
   /* the content of the struct is for halrf */
   struct rtw_regulation_info regu_info;
};
 
struct rtw_regulation_country_chplan {
   u8 domain_code;
   u8 domain_code_6g;
   u8 support_mode;
   /*
   * bit0: accept 11a
   * bit1: accept 11b
   * bit2: accept 11g
   * bit3: accept 11n
   * bit4: accept 11ac
   * bit5: accept 11ax
   */
   u8 tpo; /* tx power overwrite */
   bool valid;
};
 
struct chdef_2ghz {
    /* ch_def index */
    u8 idx;
 
    /* support channel list
     * support_ch[0]: bit(0~7) stands for ch(1~8)
     * support_ch[1]: bit(0~5) stands for ch (9~14)
     */
    u8 support_ch[2];
 
    /* passive ch list
     * passive[0]: bit(0~7) stands for ch(1~8)
     * passive[1]: bit(0~5) stands for ch (9~14)
     */
    u8 passive[2];
};
 
struct chdef_5ghz {
    /* ch_def index */
    u8 idx;
 
    /*
     * band1 support channel list, passive and dfs
     * bit0 stands for ch36
     * bit1 stands for ch40
     * bit2 stands for ch44
     * bit3 stands for ch48
     */
    u8 support_ch_b1;
    u8 passive_b1;
    u8 dfs_b1;
 
    /*
     * band2 support channel list, passive and dfs
     * bit0 stands for ch52
     * bit1 stands for ch56
     * bit2 stands for ch60
     * bit3 stands for ch64
     */
    u8 support_ch_b2;
    u8 passive_b2;
    u8 dfs_b2;
 
    /*
     * band3 support channel list, passive and dfs
     * byte[0]:
     *    bit0 stands for ch100
     *     bit1 stands for ch104
     *     bit2 stands for ch108
     *     bit3 stands for ch112
     *     bit4 stands for ch116
     *     bit5 stands for ch120
     *     bit6 stands for ch124
     *     bit7 stands for ch128
     * byte[1]:
     *    bit0 stands for ch132
     *     bit1 stands for ch136
     *     bit2 stands for ch140
     *     bit3 stands for ch144
     */
    u8 support_ch_b3[2];
    u8 passive_b3[2];
    u8 dfs_b3[2];
 
    /*
     * band4 support channel list, passive and dfs
     * bit0 stands for ch149
     * bit1 stands for ch153
     * bit2 stands for ch157
     * bit3 stands for ch161
     * bit4 stands for ch165
     * bit5 stands for ch169
     * bit6 stands for ch173
     * bit7 stands for ch177
     */
    u8 support_ch_b4;
    u8 passive_b4;
    u8 dfs_b4;
};
 
struct freq_plan {
    u8 regulation;
    u8 ch_idx;
};
 
struct regulatory_domain_mapping {
    u8 domain_code;
    struct freq_plan freq_2g;
    struct freq_plan freq_5g;
};
 
#define COUNTRY_CODE_LEN 2
struct country_domain_mapping {
    u8 domain_code;
    u8 domain_code_6g;
    char char2[COUNTRY_CODE_LEN];
    u8 tpo; /* tx power overwrite */
 
    /*
     * bit0: accept 11bgn
     * bit1: accept 11a
     * bit2: accept 11ac
     * bit3: accept 11ax
     */
    u8 support;
    u8 country_property;
 
    /*
     * bit0: support LPI
     * bit1: support SP
     * bit2: support VLP
     */
    u8 category_6g;
    u8 others_module_rf_approval;
};
 
/*
 * 6 GHz channel group from UNII-5 to UNII-8
 * channel index diff is 4 : minimum working bandwidth : 20 MHz
 * => next channel index = current index + 4
 */
 
struct chdef_6ghz {
    /* ch_def index */
    u8 idx;
 
    /*
     * UNII-5 support channel list, ch1 ~ ch93, total : 24
     * bit0 stands for ch1
     * bit1 stands for ch5
     * bit2 stands for ch9
     * ...
     * bit23 stands for ch93
     */
    u8 support_ch_u5[3];
    u8 passive_u5[3];
 
    /*
     * UNII-6 support channel list, ch97 ~ ch117, total : 6
     * bit0 stands for ch97
     * bit1 stands for ch101
     * bit2 stands for ch105
     * bit3 stands for ch109
     * bit4 stands for ch113
     * bit5 stands for ch117
     */
    u8 support_ch_u6;
    u8 passive_u6;
 
    /*
     * UNII-7 support channel list, ch121 ~ ch189, total : 18
     * bit0 stands for ch121
     * bit1 stands for ch125
     * bit2 stands for ch129
     * ...
     * bit17 stands for ch189
     */
    u8 support_ch_u7[3];
    u8 passive_u7[3];
 
    /*
     * UNII-8 support channel list, ch193 ~ ch237, total : 12
     * bit0 stands for ch193
     * bit1 stands for ch197
     * bit2 stands for ch201
     * ...
     * bit10 stands for ch233
     */
    u8 support_ch_u8[2];
    u8 passive_u8[2];
};
 
struct regulatory_domain_mapping_6g {
    u8 domain_code;
    u8 regulation;
    u8 ch_idx;
};
 
struct rtw_regu_policy {
   u8 valid_6g_bp; /* 1: valid, 0: invalid */
   u8 cp_6g_bp[MAX_CNTRY_NUM]; /* the country property for 6g band policy */
   u8 valid_5g_bp; /* 1: valid, 0: invalid */
   u8 cp_5g_bp[MAX_CNTRY_NUM]; /* the country property for 5g band policy */
};
 
enum TP_OVERWRITE {
    TPO_CHILE = 0,
    TPO_UK = 1,
    TPO_QATAR = 2,
    TPO_UKRAINE = 3,
    TPO_CN = 4,
    TPO_NA = 5
};
 
enum REGULATION {
    REGULATION_WW        =  0,
    REGULATION_ETSI      =  1,
    REGULATION_FCC       =  2,
    REGULATION_MKK       =  3,
    REGULATION_KCC       =  4,
    REGULATION_NCC       =  5,
    REGULATION_ACMA      =  6,
    REGULATION_NA        =  7,
    REGULATION_IC        =  8,
    REGULATION_CHILE     =  9,
    REGULATION_MEX       = 10,
    REGULATION_MAX       = 11,
};
 
enum rtw_regulation_table_index {
   CMN_TBL = 0x0,
   IC_TBL,
};
 
struct rtw_chplan_update_info_2g {
   u8 ch_idx;
   u8 regulation;
   u16 ch;
   u16 passive;
   bool valid;
};
 
struct rtw_chplan_update_info_5g {
   u8 ch_idx;
   u8 regulation;
   u16 ch;
   u16 passive;
   u16 dfs;
   u8 max_num;
   u8 ch_start;
   bool valid;
};
 
/*
 * NOTE:
 *     This api prototype will be removed after hal related API/header is added
 *     for halrf.
 */
bool rtw_phl_query_regulation_info(void *phl, struct rtw_regulation_info *info);
 
u8 regu_calculate_group_cntry_num(
   struct rtw_regu_policy *policy, u8 group_id,
   u8 rdmap_size, u8 cdmap_size,
   const struct regulatory_domain_mapping *rdmap_tbl,
   const struct country_domain_mapping *cdmap_tbl);
 
void regu_fill_specific_group_cntry_list(
   struct rtw_regu_policy *policy, char* list, u32 group_size,
   u8 group_id, u8 rdmap_size, u8 cdmap_size,
   const struct regulatory_domain_mapping *rdmap_tbl,
   const struct country_domain_mapping *cdmap_tbl);
 
void
regu_fill_chnlplan_content(char *country, u8 size,
   struct rtw_regulation_country_chplan *chnlplan,
   const struct country_domain_mapping *cdmap_tbl);
 
void
regu_get_chplan_update_result_2g(u8 did, u8 size,
   struct rtw_chplan_update_info_2g *info,
   const struct regulatory_domain_mapping *rdmap_tbl,
   const struct chdef_2ghz *chdef_tbl);
 
void
regu_get_chplan_update_result_5g(
   u8 group, u8 did, u8 size,
 
   struct rtw_chplan_update_info_5g *info,
   const struct regulatory_domain_mapping *rdmap_tbl,
   const struct chdef_5ghz *chdef_tbl);
 
void
regu_get_chdef_6g(
   u8 did, u8 size, struct chdef_6ghz *chdef,
   const struct chdef_6ghz *chdef_tbl);
 
#endif /* _PHL_REGULATION_DEF_H_ */