upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / staging / rtl8192e / ieee80211 / rtl819x_Qos.h
1 #ifndef __INC_QOS_TYPE_H
2 #define __INC_QOS_TYPE_H
3
4 #define BIT0                    0x00000001
5 #define BIT1                    0x00000002
6 #define BIT2                    0x00000004
7 #define BIT3                    0x00000008
8 #define BIT4                    0x00000010
9 #define BIT5                    0x00000020
10 #define BIT6                    0x00000040
11 #define BIT7                    0x00000080
12 #define BIT8                    0x00000100
13 #define BIT9                    0x00000200
14 #define BIT10                   0x00000400
15 #define BIT11                   0x00000800
16 #define BIT12                   0x00001000
17 #define BIT13                   0x00002000
18 #define BIT14                   0x00004000
19 #define BIT15                   0x00008000
20 #define BIT16                   0x00010000
21 #define BIT17                   0x00020000
22 #define BIT18                   0x00040000
23 #define BIT19                   0x00080000
24 #define BIT20                   0x00100000
25 #define BIT21                   0x00200000
26 #define BIT22                   0x00400000
27 #define BIT23                   0x00800000
28 #define BIT24                   0x01000000
29 #define BIT25                   0x02000000
30 #define BIT26                   0x04000000
31 #define BIT27                   0x08000000
32 #define BIT28                   0x10000000
33 #define BIT29                   0x20000000
34 #define BIT30                   0x40000000
35 #define BIT31                   0x80000000
36
37 #define MAX_WMMELE_LENGTH       64
38
39 //
40 // QoS mode.
41 // enum 0, 1, 2, 4: since we can use the OR(|) operation.
42 //
43 // QOS_MODE is redefined for enum can't be ++, | under C++ compiler, 2006.05.17, by rcnjko.
44 //typedef       enum _QOS_MODE{
45 //      QOS_DISABLE             = 0,
46 //      QOS_WMM                 = 1,
47 //      QOS_EDCA                        = 2,
48 //      QOS_HCCA                        = 4,
49 //}QOS_MODE,*PQOS_MODE;
50 //
51 typedef u32 QOS_MODE, *PQOS_MODE;
52 #define QOS_DISABLE             0
53 #define QOS_WMM                 1
54 #define QOS_WMMSA               2
55 #define QOS_EDCA                4
56 #define QOS_HCCA                8
57 #define QOS_WMM_UAPSD           16   //WMM Power Save, 2006-06-14 Isaiah
58
59 #define AC_PARAM_SIZE   4
60 #define WMM_PARAM_ELE_BODY_LEN  18
61
62 //
63 // QoS ACK Policy Field Values
64 // Ref: WMM spec 2.1.6: QoS Control Field, p.10.
65 //
66 typedef enum _ACK_POLICY{
67         eAckPlc0_ACK            = 0x00,
68         eAckPlc1_NoACK          = 0x01,
69 }ACK_POLICY,*PACK_POLICY;
70
71 #define WMM_PARAM_ELEMENT_SIZE  (8+(4*AC_PARAM_SIZE))
72
73 //
74 // QoS Control Field
75 // Ref:
76 //      1. WMM spec 2.1.6: QoS Control Field, p.9.
77 //      2. 802.11e/D13.0 7.1.3.5, p.26.
78 //
79 typedef union _QOS_CTRL_FIELD{
80         u8      charData[2];
81         u16     shortData;
82
83         // WMM spec
84         struct
85         {
86                 u8              UP:3;
87                 u8              usRsvd1:1;
88                 u8              EOSP:1;
89                 u8              AckPolicy:2;
90                 u8              usRsvd2:1;
91                 u8              ucRsvdByte;
92         }WMM;
93
94         // 802.11e: QoS data type frame sent by non-AP QSTAs.
95         struct
96         {
97                 u8              TID:4;
98                 u8              bIsQsize:1;// 0: BIT[8:15] is TXOP Duration Requested, 1: BIT[8:15] is Queue Size.
99                 u8              AckPolicy:2;
100                 u8              usRsvd:1;
101                 u8              TxopOrQsize;    // (BIT4=0)TXOP Duration Requested or (BIT4=1)Queue Size.
102         }BySta;
103
104         // 802.11e: QoS data, QoS Null, and QoS Data+CF-Ack frames sent by HC.
105         struct
106         {
107                 u8              TID:4;
108                 u8              EOSP:1;
109                 u8              AckPolicy:2;
110                 u8              usRsvd:1;
111                 u8              PSBufState;             // QAP PS Buffer State.
112         }ByHc_Data;
113
114         // 802.11e: QoS (+) CF-Poll frames sent by HC.
115         struct
116         {
117                 u8              TID:4;
118                 u8              EOSP:1;
119                 u8              AckPolicy:2;
120                 u8              usRsvd:1;
121                 u8              TxopLimit;              // TXOP Limit.
122         }ByHc_CFP;
123
124 }QOS_CTRL_FIELD, *PQOS_CTRL_FIELD;
125
126
127 //
128 // QoS Info Field
129 // Ref:
130 //      1. WMM spec 2.2.1: WME Information Element, p.11.
131 //      2. 8185 QoS code: QOS_INFO [def. in QoS_mp.h]
132 //
133 typedef union _QOS_INFO_FIELD{
134         u8      charData;
135
136         struct
137         {
138                 u8              ucParameterSetCount:4;
139                 u8              ucReserved:4;
140         }WMM;
141
142         struct
143         {
144                 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah
145                 u8              ucAC_VO_UAPSD:1;
146                 u8              ucAC_VI_UAPSD:1;
147                 u8              ucAC_BE_UAPSD:1;
148                 u8              ucAC_BK_UAPSD:1;
149                 u8              ucReserved1:1;
150                 u8              ucMaxSPLen:2;
151                 u8              ucReserved2:1;
152
153         }ByWmmPsSta;
154
155         struct
156         {
157                 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah
158                 u8              ucParameterSetCount:4;
159                 u8              ucReserved:3;
160                 u8              ucApUapsd:1;
161         }ByWmmPsAp;
162
163         struct
164         {
165                 u8              ucAC3_UAPSD:1;
166                 u8              ucAC2_UAPSD:1;
167                 u8              ucAC1_UAPSD:1;
168                 u8              ucAC0_UAPSD:1;
169                 u8              ucQAck:1;
170                 u8              ucMaxSPLen:2;
171                 u8              ucMoreDataAck:1;
172         } By11eSta;
173
174         struct
175         {
176                 u8              ucParameterSetCount:4;
177                 u8              ucQAck:1;
178                 u8              ucQueueReq:1;
179                 u8              ucTXOPReq:1;
180                 u8              ucReserved:1;
181         } By11eAp;
182
183         struct
184         {
185                 u8              ucReserved1:4;
186                 u8              ucQAck:1;
187                 u8              ucReserved2:2;
188                 u8              ucMoreDataAck:1;
189         } ByWmmsaSta;
190
191         struct
192         {
193                 u8              ucReserved1:4;
194                 u8              ucQAck:1;
195                 u8              ucQueueReq:1;
196                 u8              ucTXOPReq:1;
197                 u8              ucReserved2:1;
198         } ByWmmsaAp;
199
200         struct
201         {
202                 u8              ucAC3_UAPSD:1;
203                 u8              ucAC2_UAPSD:1;
204                 u8              ucAC1_UAPSD:1;
205                 u8              ucAC0_UAPSD:1;
206                 u8              ucQAck:1;
207                 u8              ucMaxSPLen:2;
208                 u8              ucMoreDataAck:1;
209         } ByAllSta;
210
211         struct
212         {
213                 u8              ucParameterSetCount:4;
214                 u8              ucQAck:1;
215                 u8              ucQueueReq:1;
216                 u8              ucTXOPReq:1;
217                 u8              ucApUapsd:1;
218         } ByAllAp;
219
220 }QOS_INFO_FIELD, *PQOS_INFO_FIELD;
221
222 //
223 // ACI to AC coding.
224 // Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
225 //
226 // AC_CODING is redefined for enum can't be ++, | under C++ compiler, 2006.05.17, by rcnjko.
227 //typedef       enum _AC_CODING{
228 //      AC0_BE  = 0,            // ACI: 0x00    // Best Effort
229 //      AC1_BK  = 1,            // ACI: 0x01    // Background
230 //      AC2_VI  = 2,            // ACI: 0x10    // Video
231 //      AC3_VO  = 3,            // ACI: 0x11    // Voice
232 //      AC_MAX = 4,             // Max: define total number; Should not to be used as a real enum.
233 //}AC_CODING,*PAC_CODING;
234 //
235 typedef u32 AC_CODING;
236 #define AC0_BE  0               // ACI: 0x00    // Best Effort
237 #define AC1_BK  1               // ACI: 0x01    // Background
238 #define AC2_VI  2               // ACI: 0x10    // Video
239 #define AC3_VO  3               // ACI: 0x11    // Voice
240 #define AC_MAX  4               // Max: define total number; Should not to be used as a real enum.
241
242 //
243 // ACI/AIFSN Field.
244 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
245 //
246 typedef union _ACI_AIFSN{
247         u8      charData;
248
249         struct
250         {
251                 u8      AIFSN:4;
252                 u8      ACM:1;
253                 u8      ACI:2;
254                 u8      Reserved:1;
255         }f;     // Field
256 }ACI_AIFSN, *PACI_AIFSN;
257
258 //
259 // ECWmin/ECWmax field.
260 // Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
261 //
262 typedef union _ECW{
263         u8      charData;
264         struct
265         {
266                 u8      ECWmin:4;
267                 u8      ECWmax:4;
268         }f;     // Field
269 }ECW, *PECW;
270
271 //
272 // AC Parameters Record Format.
273 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
274 //
275 typedef union _AC_PARAM{
276         u32     longData;
277         u8      charData[4];
278
279         struct
280         {
281                 ACI_AIFSN       AciAifsn;
282                 ECW             Ecw;
283                 u16             TXOPLimit;
284         }f;     // Field
285 }AC_PARAM, *PAC_PARAM;
286
287
288
289 //
290 // QoS element subtype
291 //
292 typedef enum _QOS_ELE_SUBTYPE{
293         QOSELE_TYPE_INFO        = 0x00,         // 0x00: Information element
294         QOSELE_TYPE_PARAM       = 0x01,         // 0x01: parameter element
295 }QOS_ELE_SUBTYPE,*PQOS_ELE_SUBTYPE;
296
297
298 //
299 // Direction Field Values.
300 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
301 //
302 typedef enum _DIRECTION_VALUE{
303         DIR_UP                  = 0,            // 0x00 // UpLink
304         DIR_DOWN                = 1,            // 0x01 // DownLink
305         DIR_DIRECT              = 2,            // 0x10 // DirectLink
306         DIR_BI_DIR              = 3,            // 0x11 // Bi-Direction
307 }DIRECTION_VALUE,*PDIRECTION_VALUE;
308
309
310 //
311 // TS Info field in WMM TSPEC Element.
312 // Ref:
313 //      1. WMM spec 2.2.11: WME TSPEC Element, p.18.
314 //      2. 8185 QoS code: QOS_TSINFO [def. in QoS_mp.h]
315 //
316 typedef union _QOS_TSINFO{
317         u8              charData[3];
318         struct {
319                 u8              ucTrafficType:1;                        //WMM is reserved
320                 u8              ucTSID:4;
321                 u8              ucDirection:2;
322                 u8              ucAccessPolicy:2;       //WMM: bit8=0, bit7=1
323                 u8              ucAggregation:1;                //WMM is reserved
324                 u8              ucPSB:1;                                //WMMSA is APSD
325                 u8              ucUP:3;
326                 u8              ucTSInfoAckPolicy:2;            //WMM is reserved
327                 u8              ucSchedule:1;                   //WMM is reserved
328                 u8              ucReserved:7;
329         }field;
330 }QOS_TSINFO, *PQOS_TSINFO;
331
332 //
333 // WMM TSPEC Body.
334 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.16.
335 //
336 typedef union _TSPEC_BODY{
337         u8              charData[55];
338
339         struct
340         {
341                 QOS_TSINFO      TSInfo; //u8    TSInfo[3];
342                 u16     NominalMSDUsize;
343                 u16     MaxMSDUsize;
344                 u32     MinServiceItv;
345                 u32     MaxServiceItv;
346                 u32     InactivityItv;
347                 u32     SuspenItv;
348                 u32     ServiceStartTime;
349                 u32     MinDataRate;
350                 u32     MeanDataRate;
351                 u32     PeakDataRate;
352                 u32     MaxBurstSize;
353                 u32     DelayBound;
354                 u32     MinPhyRate;
355                 u16     SurplusBandwidthAllowance;
356                 u16     MediumTime;
357         } f;    // Field
358 }TSPEC_BODY, *PTSPEC_BODY;
359
360
361 //
362 // WMM TSPEC Element.
363 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.16.
364 //
365 typedef struct _WMM_TSPEC{
366         u8              ID;
367         u8              Length;
368         u8              OUI[3];
369         u8              OUI_Type;
370         u8              OUI_SubType;
371         u8              Version;
372         TSPEC_BODY      Body;
373 } WMM_TSPEC, *PWMM_TSPEC;
374
375 //
376 // ACM implementation method.
377 // Annie, 2005-12-13.
378 //
379 typedef enum _ACM_METHOD{
380         eAcmWay0_SwAndHw                = 0,            // By SW and HW.
381         eAcmWay1_HW                     = 1,            // By HW.
382         eAcmWay2_SW                     = 2,            // By SW.
383 }ACM_METHOD,*PACM_METHOD;
384
385
386 typedef struct _ACM{
387 //      u8              RegEnableACM;
388         u64             UsedTime;
389         u64             MediumTime;
390         u8              HwAcmCtl;       // TRUE: UsedTime exceed => Do NOT USE this AC. It wll be written to ACM_CONTROL(0xBF BIT 0/1/2 in 8185B).
391 }ACM, *PACM;
392
393 typedef u8              AC_UAPSD, *PAC_UAPSD;
394
395 #define GET_VO_UAPSD(_apsd) ((_apsd) & BIT0)
396 #define SET_VO_UAPSD(_apsd) ((_apsd) |= BIT0)
397
398 #define GET_VI_UAPSD(_apsd) ((_apsd) & BIT1)
399 #define SET_VI_UAPSD(_apsd) ((_apsd) |= BIT1)
400
401 #define GET_BK_UAPSD(_apsd) ((_apsd) & BIT2)
402 #define SET_BK_UAPSD(_apsd) ((_apsd) |= BIT2)
403
404 #define GET_BE_UAPSD(_apsd) ((_apsd) & BIT3)
405 #define SET_BE_UAPSD(_apsd) ((_apsd) |= BIT3)
406
407
408 //typedef struct _TCLASS{
409 // TODO
410 //} TCLASS, *PTCLASS;
411 typedef union _QOS_TCLAS{
412
413         struct _TYPE_GENERAL{
414                 u8              Priority;
415                 u8              ClassifierType;
416                 u8              Mask;
417         } TYPE_GENERAL;
418
419         struct _TYPE0_ETH{
420                 u8              Priority;
421                 u8              ClassifierType;
422                 u8              Mask;
423                 u8              SrcAddr[6];
424                 u8              DstAddr[6];
425                 u16             Type;
426         } TYPE0_ETH;
427
428         struct _TYPE1_IPV4{
429                 u8              Priority;
430                 u8              ClassifierType;
431                 u8              Mask;
432                 u8              Version;
433                 u8              SrcIP[4];
434                 u8              DstIP[4];
435                 u16             SrcPort;
436                 u16             DstPort;
437                 u8              DSCP;
438                 u8              Protocol;
439                 u8              Reserved;
440         } TYPE1_IPV4;
441
442         struct _TYPE1_IPV6{
443                 u8              Priority;
444                 u8              ClassifierType;
445                 u8              Mask;
446                 u8              Version;
447                 u8              SrcIP[16];
448                 u8              DstIP[16];
449                 u16             SrcPort;
450                 u16             DstPort;
451                 u8              FlowLabel[3];
452         } TYPE1_IPV6;
453
454         struct _TYPE2_8021Q{
455                 u8              Priority;
456                 u8              ClassifierType;
457                 u8              Mask;
458                 u16             TagType;
459         } TYPE2_8021Q;
460 } QOS_TCLAS, *PQOS_TCLAS;
461
462 //typedef struct _WMM_TSTREAM{
463 //
464 //- TSPEC
465 //- AC (which to mapping)
466 //} WMM_TSTREAM, *PWMM_TSTREAM;
467 typedef struct _QOS_TSTREAM{
468         u8                      AC;
469         WMM_TSPEC               TSpec;
470         QOS_TCLAS               TClass;
471 } QOS_TSTREAM, *PQOS_TSTREAM;
472
473 //typedef struct _U_APSD{
474 //- TriggerEnable [4]
475 //- MaxSPLength
476 //- HighestAcBuffered
477 //} U_APSD, *PU_APSD;
478
479 //joseph TODO:
480 //      UAPSD function should be implemented by 2 data structure
481 //      "Qos control field" and "Qos info field"
482 //typedef struct _QOS_UAPSD{
483 //      u8                      bTriggerEnable[4];
484 //      u8                      MaxSPLength;
485 //      u8                      HighestBufAC;
486 //} QOS_UAPSD, *PQOS_APSD;
487
488 //----------------------------------------------------------------------------
489 //      802.11 Management frame Status Code field
490 //----------------------------------------------------------------------------
491 typedef struct _OCTET_STRING{
492         u8              *Octet;
493         u16             Length;
494 }OCTET_STRING, *POCTET_STRING;
495
496 //
497 // STA QoS data.
498 // Ref: DOT11_QOS in 8185 code. [def. in QoS_mp.h]
499 //
500 typedef struct _STA_QOS{
501         //DECLARE_RT_OBJECT(STA_QOS);
502         u8                              WMMIEBuf[MAX_WMMELE_LENGTH];
503         u8*                             WMMIE;
504
505         // Part 1. Self QoS Mode.
506         QOS_MODE                        QosCapability; //QoS Capability, 2006-06-14 Isaiah
507         QOS_MODE                        CurrentQosMode;
508
509         // For WMM Power Save Mode :
510         // ACs are trigger/delivery enabled or legacy power save enabled. 2006-06-13 Isaiah
511         AC_UAPSD                        b4ac_Uapsd;  //VoUapsd(bit0), ViUapsd(bit1),  BkUapsd(bit2), BeUapsd(bit3),
512         AC_UAPSD                        Curr4acUapsd;
513         u8                              bInServicePeriod;
514         u8                              MaxSPLength;
515         int                             NumBcnBeforeTrigger;
516
517         // Part 2. EDCA Parameter (perAC)
518         u8 *                            pWMMInfoEle;
519         u8                              WMMParamEle[WMM_PARAM_ELEMENT_SIZE];
520         u8                              WMMPELength;
521
522         // <Bruce_Note>
523         //2 ToDo: remove the Qos Info Field and replace it by the above WMM Info element.
524         // By Bruce, 2008-01-30.
525         // Part 2. EDCA Parameter (perAC)
526         QOS_INFO_FIELD                  QosInfoField_STA;       // Maintained by STA
527         QOS_INFO_FIELD                  QosInfoField_AP;        // Retrieved from AP
528
529         AC_PARAM                        CurAcParameters[4];
530
531         // Part 3. ACM
532         ACM                             acm[4];
533         ACM_METHOD                      AcmMethod;
534
535         // Part 4. Per TID (Part 5: TCLASS will be described by TStream)
536         QOS_TSTREAM                     TStream[16];
537         WMM_TSPEC                       TSpec;
538
539         u32                             QBssWirelessMode;
540
541         // No Ack Setting
542         u8                              bNoAck;
543
544         // Enable/Disable Rx immediate BA capability.
545         u8                              bEnableRxImmBA;
546
547 }STA_QOS, *PSTA_QOS;
548
549 //
550 // BSS QOS data.
551 // Ref: BssDscr in 8185 code. [def. in BssDscr.h]
552 //
553 typedef struct _BSS_QOS{
554         QOS_MODE                bdQoSMode;
555
556         u8                      bdWMMIEBuf[MAX_WMMELE_LENGTH];
557         u8*             bdWMMIE;
558
559         QOS_ELE_SUBTYPE         EleSubType;
560
561         u8 *                    pWMMInfoEle;
562         u8 *                    pWMMParamEle;
563
564         QOS_INFO_FIELD          QosInfoField;
565         AC_PARAM                AcParameter[4];
566 }BSS_QOS, *PBSS_QOS;
567
568
569 //
570 // Ref: sQoSCtlLng and QoSCtl definition in 8185 QoS code.
571 //#define QoSCtl   ((   (Adapter->bRegQoS) && (Adapter->dot11QoS.QoSMode &(QOS_EDCA|QOS_HCCA))    )  ?sQoSCtlLng:0)
572 //
573 #define sQoSCtlLng                      2
574 #define QOS_CTRL_LEN(_QosMode)          ((_QosMode > QOS_DISABLE)? sQoSCtlLng : 0)
575
576
577 //Added by joseph
578 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
579 //#define UP2AC(up)                     ((up<3)?((up==0)?1:0):(up>>1))
580 #define IsACValid(ac)                   ((ac<=7 )?true:false )
581
582 #endif // #ifndef __INC_QOS_TYPE_H