Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

wpa_psk.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <string.h>
  21. #include <ipxe/net80211.h>
  22. #include <ipxe/sha1.h>
  23. #include <ipxe/wpa.h>
  24. #include <errno.h>
  25. /** @file
  26. *
  27. * Frontend for WPA using a pre-shared key.
  28. */
  29. /**
  30. * Initialise WPA-PSK state
  31. *
  32. * @v dev 802.11 device
  33. * @ret rc Return status code
  34. */
  35. static int wpa_psk_init ( struct net80211_device *dev )
  36. {
  37. return wpa_make_rsn_ie ( dev, &dev->rsn_ie );
  38. }
  39. /**
  40. * Start WPA-PSK authentication
  41. *
  42. * @v dev 802.11 device
  43. * @ret rc Return status code
  44. */
  45. static int wpa_psk_start ( struct net80211_device *dev )
  46. {
  47. char passphrase[64+1];
  48. u8 pmk[WPA_PMK_LEN];
  49. int len;
  50. struct wpa_common_ctx *ctx = dev->handshaker->priv;
  51. len = fetch_string_setting ( netdev_settings ( dev->netdev ),
  52. &net80211_key_setting, passphrase,
  53. 64 + 1 );
  54. if ( len <= 0 ) {
  55. DBGC ( ctx, "WPA-PSK %p: no passphrase provided!\n", ctx );
  56. net80211_deauthenticate ( dev, -EACCES );
  57. return -EACCES;
  58. }
  59. pbkdf2_sha1 ( passphrase, len, dev->essid, strlen ( dev->essid ),
  60. 4096, pmk, WPA_PMK_LEN );
  61. DBGC ( ctx, "WPA-PSK %p: derived PMK from passphrase `%s':\n", ctx,
  62. passphrase );
  63. DBGC_HD ( ctx, pmk, WPA_PMK_LEN );
  64. return wpa_start ( dev, ctx, pmk, WPA_PMK_LEN );
  65. }
  66. /**
  67. * Step WPA-PSK authentication
  68. *
  69. * @v dev 802.11 device
  70. * @ret rc Return status code
  71. */
  72. static int wpa_psk_step ( struct net80211_device *dev )
  73. {
  74. struct wpa_common_ctx *ctx = dev->handshaker->priv;
  75. switch ( ctx->state ) {
  76. case WPA_SUCCESS:
  77. return 1;
  78. case WPA_FAILURE:
  79. return -EACCES;
  80. default:
  81. return 0;
  82. }
  83. }
  84. /**
  85. * Do-nothing function; you can't change a WPA key post-authentication
  86. *
  87. * @v dev 802.11 device
  88. * @ret rc Return status code
  89. */
  90. static int wpa_psk_no_change_key ( struct net80211_device *dev __unused )
  91. {
  92. return 0;
  93. }
  94. /**
  95. * Disable handling of received WPA authentication frames
  96. *
  97. * @v dev 802.11 device
  98. */
  99. static void wpa_psk_stop ( struct net80211_device *dev )
  100. {
  101. wpa_stop ( dev );
  102. }
  103. /** WPA-PSK security handshaker */
  104. struct net80211_handshaker wpa_psk_handshaker __net80211_handshaker = {
  105. .protocol = NET80211_SECPROT_PSK,
  106. .init = wpa_psk_init,
  107. .start = wpa_psk_start,
  108. .step = wpa_psk_step,
  109. .change_key = wpa_psk_no_change_key,
  110. .stop = wpa_psk_stop,
  111. .priv_len = sizeof ( struct wpa_common_ctx ),
  112. };