rtw_wapi.h 6.5 KB

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