rtw_wapi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #ifndef __INC_WAPI_H
  2. #define __INC_WAPI_H
  3. #define CONFIG_WAPI_SW_SMS4
  4. #define WAPI_DEBUG
  5. #define SMS4_MIC_LEN 16
  6. #define WAPI_EXT_LEN 18
  7. #define MAX_WAPI_IE_LEN 256
  8. #define sMacHdrLng 24 // octets in data header, no WEP
  9. #ifdef WAPI_DEBUG
  10. /* WAPI trace debug */
  11. extern u32 wapi_debug_component;
  12. static inline void dump_buf(u8 *buf, u32 len)
  13. {
  14. u32 i;
  15. printk("-----------------Len %d----------------\n", len);
  16. for(i=0; i<len; i++)
  17. printk("%2.2x-", *(buf+i));
  18. printk("\n");
  19. }
  20. #define WAPI_TRACE(component, x, args...) \
  21. do { if(wapi_debug_component & (component)) \
  22. printk(KERN_DEBUG "WAPI" ":" x "" , \
  23. ##args);\
  24. }while(0);
  25. #define WAPI_DATA(component, x, buf, len) \
  26. do { if(wapi_debug_component & (component)){ \
  27. printk("%s:\n", x);\
  28. dump_buf((buf), (len));}\
  29. }while(0);
  30. #define RT_ASSERT_RET(_Exp) \
  31. if(!(_Exp)) \
  32. { \
  33. printk("RTWLAN: "); \
  34. printk( "Assertion failed! %s,%s,line=%d\n", \
  35. #_Exp,__FUNCTION__,__LINE__); \
  36. return; \
  37. }
  38. #define RT_ASSERT_RET_VALUE(_Exp,Ret) \
  39. if(!(_Exp)) \
  40. { \
  41. printk("RTWLAN: "); \
  42. printk( "Assertion failed! %s,%s,line=%d\n", \
  43. #_Exp,__FUNCTION__,__LINE__); \
  44. return (Ret); \
  45. }
  46. #else
  47. #define RT_ASSERT_RET(_Exp) do {} while(0)
  48. #define RT_ASSERT_RET_VALUE(_Exp,Ret) do {} while(0)
  49. #define WAPI_TRACE(component, x, args...) do {} while(0)
  50. #define WAPI_DATA(component, x, buf, len) do {} while(0)
  51. #endif
  52. enum WAPI_DEBUG {
  53. WAPI_INIT = 1,
  54. WAPI_API = 1<<1,
  55. WAPI_TX = 1<<2,
  56. WAPI_RX = 1<<3,
  57. WAPI_MLME = 1<<4,
  58. WAPI_IOCTL = 1<<5,
  59. WAPI_ERR = 1<<31
  60. };
  61. #define WAPI_MAX_BKID_NUM 4
  62. #define WAPI_MAX_STAINFO_NUM 4
  63. #define WAPI_CAM_ENTRY_NUM 14 // 28/2=14
  64. typedef struct _RT_WAPI_BKID
  65. {
  66. struct list_head list;
  67. u8 bkid[16];
  68. }RT_WAPI_BKID,*PRT_WAPI_BKID;
  69. typedef struct _RT_WAPI_KEY
  70. {
  71. u8 dataKey[16];
  72. u8 micKey[16];
  73. u8 keyId;
  74. bool bSet;
  75. bool bTxEnable;
  76. }RT_WAPI_KEY,*PRT_WAPI_KEY;
  77. typedef enum _RT_WAPI_PACKET_TYPE
  78. {
  79. WAPI_NONE = 0,
  80. WAPI_PREAUTHENTICATE=1,
  81. WAPI_STAKEY_REQUEST=2,
  82. WAPI_AUTHENTICATE_ACTIVE=3,
  83. WAPI_ACCESS_AUTHENTICATE_REQUEST=4,
  84. WAPI_ACCESS_AUTHENTICATE_RESPONSE=5,
  85. WAPI_CERTIFICATE_AUTHENTICATE_REQUEST=6,
  86. WAPI_CERTIFICATE_AUTHENTICATE_RESPONSE=7,
  87. WAPI_USK_REQUEST=8,
  88. WAPI_USK_RESPONSE=9,
  89. WAPI_USK_CONFIRM=10,
  90. WAPI_MSK_NOTIFICATION=11,
  91. WAPI_MSK_RESPONSE=12
  92. }RT_WAPI_PACKET_TYPE;
  93. typedef struct _RT_WAPI_STA_INFO
  94. {
  95. struct list_head list;
  96. u8 PeerMacAddr[6];
  97. RT_WAPI_KEY wapiUsk;
  98. RT_WAPI_KEY wapiUskUpdate;
  99. RT_WAPI_KEY wapiMsk;
  100. RT_WAPI_KEY wapiMskUpdate;
  101. u8 lastRxUnicastPN[16];
  102. u8 lastTxUnicastPN[16];
  103. u8 lastRxMulticastPN[16];
  104. u8 lastRxUnicastPNBEQueue[16];
  105. u8 lastRxUnicastPNBKQueue[16];
  106. u8 lastRxUnicastPNVIQueue[16];
  107. u8 lastRxUnicastPNVOQueue[16];
  108. bool bSetkeyOk;
  109. bool bAuthenticateInProgress;
  110. bool bAuthenticatorInUpdata;
  111. }RT_WAPI_STA_INFO,*PRT_WAPI_STA_INFO;
  112. //Added for HW wapi en/decryption
  113. typedef struct _RT_WAPI_CAM_ENTRY{
  114. //RT_LIST_ENTRY list;
  115. u8 IsUsed;
  116. u8 entry_idx;//for cam entry
  117. u8 keyidx; // 0 or 1,new or old key
  118. u8 PeerMacAddr[6];
  119. u8 type; //should be 110,wapi
  120. }RT_WAPI_CAM_ENTRY,*PRT_WAPI_CAM_ENTRY;
  121. typedef struct _RT_WAPI_T
  122. {
  123. //BKID
  124. RT_WAPI_BKID wapiBKID[WAPI_MAX_BKID_NUM];
  125. struct list_head wapiBKIDIdleList;
  126. struct list_head wapiBKIDStoreList;
  127. //Key for Tx Multicast/Broadcast
  128. RT_WAPI_KEY wapiTxMsk;
  129. //sec related
  130. u8 lastTxMulticastPN[16];
  131. //STA list
  132. RT_WAPI_STA_INFO wapiSta[WAPI_MAX_STAINFO_NUM];
  133. struct list_head wapiSTAIdleList;
  134. struct list_head wapiSTAUsedList;
  135. //
  136. bool bWapiEnable;
  137. //store WAPI IE
  138. u8 wapiIE[256];
  139. u8 wapiIELength;
  140. bool bWapiPSK;
  141. //last sequece number for wai packet
  142. u16 wapiSeqnumAndFragNum;
  143. int extra_prefix_len;
  144. int extra_postfix_len;
  145. RT_WAPI_CAM_ENTRY wapiCamEntry[WAPI_CAM_ENTRY_NUM];
  146. }RT_WAPI_T,*PRT_WAPI_T;
  147. typedef struct _WLAN_HEADER_WAPI_EXTENSION
  148. {
  149. u8 KeyIdx;
  150. u8 Reserved;
  151. u8 PN[16];
  152. } WLAN_HEADER_WAPI_EXTENSION, *PWLAN_HEADER_WAPI_EXTENSION;
  153. u32 WapiComparePN(u8 *PN1, u8 *PN2);
  154. void rtw_wapi_init(_adapter *padapter);
  155. void rtw_wapi_free(_adapter *padapter);
  156. void rtw_wapi_disable_tx(_adapter *padapter);
  157. u8 rtw_wapi_is_wai_packet(_adapter* padapter,u8 *pkt_data);
  158. void rtw_wapi_update_info(_adapter *padapter, union recv_frame *precv_frame);
  159. u8 rtw_wapi_check_for_drop(_adapter *padapter, union recv_frame *precv_frame);
  160. void rtw_build_probe_resp_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
  161. void rtw_build_beacon_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
  162. void rtw_build_assoc_req_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib);
  163. void rtw_wapi_on_assoc_ok(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
  164. void rtw_wapi_return_one_sta_info(_adapter *padapter, u8 *MacAddr);
  165. void rtw_wapi_return_all_sta_info(_adapter *padapter);
  166. void rtw_wapi_clear_cam_entry(_adapter *padapter, u8 *pMacAddr);
  167. void rtw_wapi_clear_all_cam_entry(_adapter *padapter);
  168. void rtw_wapi_set_key(_adapter *padapter, RT_WAPI_KEY *pWapiKey, RT_WAPI_STA_INFO *pWapiSta, u8 bGroupKey, u8 bUseDefaultKey);
  169. int rtw_wapi_create_event_send(_adapter *padapter, u8 EventId, u8 *MacAddr, u8 *Buff, u16 BufLen);
  170. u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe);
  171. u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe);
  172. void rtw_wapi_get_iv(_adapter *padapter, u8*pRA, u8*IV);
  173. u8 WapiIncreasePN(u8 *PN, u8 AddCount);
  174. bool rtw_wapi_drop_for_key_absent(_adapter *padapter,u8 *pRA);
  175. #endif