344-0019-brcmfmac-integrate-add_keyext-in-add_key.patch 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. From: Hante Meuleman <hante.meuleman@broadcom.com>
  2. Date: Wed, 17 Feb 2016 11:27:09 +0100
  3. Subject: [PATCH] brcmfmac: integrate add_keyext in add_key
  4. brcmf_add_keyext is called when a key is configured for a specific
  5. mac address. This function is very similar to the calling function
  6. brcmf_add_key. Integrate this function and also use existing del_key
  7. function in case key is to be cleared.
  8. Reviewed-by: Arend Van Spriel <arend.van@broadcom.com>
  9. Reviewed-by: Franky (Zhenhui) Lin <franky.lin@broadcom.com>
  10. Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
  11. Signed-off-by: Hante Meuleman <hante.meuleman@broadcom.com>
  12. Signed-off-by: Arend van Spriel <arend@broadcom.com>
  13. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  14. ---
  15. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  16. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  17. @@ -2073,84 +2073,34 @@ done:
  18. }
  19. static s32
  20. -brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
  21. - u8 key_idx, const u8 *mac_addr, struct key_params *params)
  22. +brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  23. + u8 key_idx, bool pairwise, const u8 *mac_addr)
  24. {
  25. struct brcmf_if *ifp = netdev_priv(ndev);
  26. struct brcmf_wsec_key key;
  27. s32 err = 0;
  28. - u8 keybuf[8];
  29. +
  30. + brcmf_dbg(TRACE, "Enter\n");
  31. + if (!check_vif_up(ifp->vif))
  32. + return -EIO;
  33. +
  34. + if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  35. + /* we ignore this key index in this case */
  36. + return -EINVAL;
  37. + }
  38. memset(&key, 0, sizeof(key));
  39. - key.index = (u32) key_idx;
  40. - /* Instead of bcast for ea address for default wep keys,
  41. - driver needs it to be Null */
  42. - if (!is_multicast_ether_addr(mac_addr))
  43. - memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
  44. - key.len = (u32) params->key_len;
  45. - /* check for key index change */
  46. - if (key.len == 0) {
  47. - /* key delete */
  48. - err = send_key_to_dongle(ifp, &key);
  49. - if (err)
  50. - brcmf_err("key delete error (%d)\n", err);
  51. - } else {
  52. - if (key.len > sizeof(key.data)) {
  53. - brcmf_err("Invalid key length (%d)\n", key.len);
  54. - return -EINVAL;
  55. - }
  56. - brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
  57. - memcpy(key.data, params->key, key.len);
  58. + key.index = (u32)key_idx;
  59. + key.flags = BRCMF_PRIMARY_KEY;
  60. + key.algo = CRYPTO_ALGO_OFF;
  61. - if (!brcmf_is_apmode(ifp->vif) &&
  62. - (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
  63. - brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
  64. - memcpy(keybuf, &key.data[24], sizeof(keybuf));
  65. - memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
  66. - memcpy(&key.data[16], keybuf, sizeof(keybuf));
  67. - }
  68. + brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  69. - /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
  70. - if (params->seq && params->seq_len == 6) {
  71. - /* rx iv */
  72. - u8 *ivptr;
  73. - ivptr = (u8 *) params->seq;
  74. - key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
  75. - (ivptr[3] << 8) | ivptr[2];
  76. - key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
  77. - key.iv_initialized = true;
  78. - }
  79. + /* Set the new key/index */
  80. + err = send_key_to_dongle(ifp, &key);
  81. - switch (params->cipher) {
  82. - case WLAN_CIPHER_SUITE_WEP40:
  83. - key.algo = CRYPTO_ALGO_WEP1;
  84. - brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  85. - break;
  86. - case WLAN_CIPHER_SUITE_WEP104:
  87. - key.algo = CRYPTO_ALGO_WEP128;
  88. - brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  89. - break;
  90. - case WLAN_CIPHER_SUITE_TKIP:
  91. - key.algo = CRYPTO_ALGO_TKIP;
  92. - brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  93. - break;
  94. - case WLAN_CIPHER_SUITE_AES_CMAC:
  95. - key.algo = CRYPTO_ALGO_AES_CCM;
  96. - brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  97. - break;
  98. - case WLAN_CIPHER_SUITE_CCMP:
  99. - key.algo = CRYPTO_ALGO_AES_CCM;
  100. - brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
  101. - break;
  102. - default:
  103. - brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
  104. - return -EINVAL;
  105. - }
  106. - err = send_key_to_dongle(ifp, &key);
  107. - if (err)
  108. - brcmf_err("wsec_key error (%d)\n", err);
  109. - }
  110. + brcmf_dbg(TRACE, "Exit\n");
  111. return err;
  112. }
  113. @@ -2163,8 +2113,9 @@ brcmf_cfg80211_add_key(struct wiphy *wip
  114. struct brcmf_wsec_key *key;
  115. s32 val;
  116. s32 wsec;
  117. - s32 err = 0;
  118. + s32 err;
  119. u8 keybuf[8];
  120. + bool ext_key;
  121. brcmf_dbg(TRACE, "Enter\n");
  122. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  123. @@ -2177,27 +2128,32 @@ brcmf_cfg80211_add_key(struct wiphy *wip
  124. return -EINVAL;
  125. }
  126. - if (mac_addr &&
  127. - (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
  128. - (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
  129. - brcmf_dbg(TRACE, "Exit");
  130. - return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
  131. - }
  132. -
  133. - key = &ifp->vif->profile.key[key_idx];
  134. - memset(key, 0, sizeof(*key));
  135. + if (params->key_len == 0)
  136. + return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise,
  137. + mac_addr);
  138. if (params->key_len > sizeof(key->data)) {
  139. brcmf_err("Too long key length (%u)\n", params->key_len);
  140. - err = -EINVAL;
  141. - goto done;
  142. + return -EINVAL;
  143. + }
  144. +
  145. + ext_key = false;
  146. + if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
  147. + (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
  148. + brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr);
  149. + ext_key = true;
  150. }
  151. +
  152. + key = &ifp->vif->profile.key[key_idx];
  153. + memset(key, 0, sizeof(*key));
  154. + if ((ext_key) && (!is_multicast_ether_addr(mac_addr)))
  155. + memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN);
  156. key->len = params->key_len;
  157. key->index = key_idx;
  158. -
  159. memcpy(key->data, params->key, key->len);
  160. + if (!ext_key)
  161. + key->flags = BRCMF_PRIMARY_KEY;
  162. - key->flags = BRCMF_PRIMARY_KEY;
  163. switch (params->cipher) {
  164. case WLAN_CIPHER_SUITE_WEP40:
  165. key->algo = CRYPTO_ALGO_WEP1;
  166. @@ -2237,7 +2193,7 @@ brcmf_cfg80211_add_key(struct wiphy *wip
  167. }
  168. err = send_key_to_dongle(ifp, key);
  169. - if (err)
  170. + if (ext_key || err)
  171. goto done;
  172. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  173. @@ -2256,38 +2212,6 @@ done:
  174. brcmf_dbg(TRACE, "Exit\n");
  175. return err;
  176. }
  177. -
  178. -static s32
  179. -brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  180. - u8 key_idx, bool pairwise, const u8 *mac_addr)
  181. -{
  182. - struct brcmf_if *ifp = netdev_priv(ndev);
  183. - struct brcmf_wsec_key key;
  184. - s32 err = 0;
  185. -
  186. - brcmf_dbg(TRACE, "Enter\n");
  187. - if (!check_vif_up(ifp->vif))
  188. - return -EIO;
  189. -
  190. - if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  191. - /* we ignore this key index in this case */
  192. - return -EINVAL;
  193. - }
  194. -
  195. - memset(&key, 0, sizeof(key));
  196. -
  197. - key.index = (u32) key_idx;
  198. - key.flags = BRCMF_PRIMARY_KEY;
  199. - key.algo = CRYPTO_ALGO_OFF;
  200. -
  201. - brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  202. -
  203. - /* Set the new key/index */
  204. - err = send_key_to_dongle(ifp, &key);
  205. -
  206. - brcmf_dbg(TRACE, "Exit\n");
  207. - return err;
  208. -}
  209. static s32
  210. brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,