wpa.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Minimal WPA2-PSK supplicant (IEEE 802.11i 4-way and group handshakes,
  2. * key descriptor version 2: HMAC-SHA1-128 MIC + AES key wrap, CCMP only).
  3. * Pure C, no OS calls: the ring-3 `wifi` command moves the EAPOL frames
  4. * (SYS_WIFI_EAPOL_RX/TX) and installs the keys. Host test: make test-wpa. */
  5. #ifndef WPA_H
  6. #define WPA_H
  7. #define WPA_NONE 0 /* frame ignored */
  8. #define WPA_REPLY 1 /* send `reply` */
  9. #define WPA_PTK 2 /* send `reply`, then install TK + GTK, authorize */
  10. #define WPA_GTK 3 /* send `reply`, then install the new GTK */
  11. #define WPA_ERR -1 /* bad MIC / replay / malformed */
  12. struct wpa_sm {
  13. unsigned char pmk[32];
  14. unsigned char aa[6], spa[6]; /* AP and our MAC */
  15. unsigned char anonce[32], snonce[32];
  16. unsigned char ptk[48]; /* KCK | KEK | TK */
  17. unsigned char replay[8];
  18. int have_replay, have_snonce, ptk_ok;
  19. unsigned char ie[64]; /* our RSN IE (assoc request) */
  20. unsigned int ie_len;
  21. unsigned char ap_ie[64]; /* AP's RSN IE (beacon) */
  22. unsigned int ap_ie_len;
  23. unsigned char gtk[32];
  24. unsigned int gtk_len;
  25. int gtk_idx;
  26. unsigned char gtk_rsc[8];
  27. const char *error;
  28. };
  29. /* PMK = PBKDF2-HMAC-SHA1(passphrase, ssid, 4096, 32). */
  30. void wpa_pmk(const char *pass, const unsigned char *ssid, unsigned int ssid_len,
  31. unsigned char pmk[32]);
  32. /* Our RSN IE: version 1, CCMP group, CCMP pairwise, PSK AKM, caps 0. */
  33. unsigned int wpa_rsn_ie(unsigned char out[22]);
  34. void wpa_init(struct wpa_sm *sm, const unsigned char pmk[32],
  35. const unsigned char aa[6], const unsigned char spa[6],
  36. const unsigned char *ie, unsigned int ie_len,
  37. const unsigned char *ap_ie, unsigned int ap_ie_len);
  38. /* Process one EAPOL frame (starting at the EAPOL header). `reply` must
  39. * hold 256 bytes. `rng` fills the SNonce. */
  40. int wpa_rx(struct wpa_sm *sm, const unsigned char *f, unsigned int len,
  41. unsigned char *reply, unsigned int *rlen,
  42. void (*rng)(unsigned char *out, unsigned int n));
  43. #define WPA_TK(sm) ((sm)->ptk + 32)
  44. #define WPA_KCK(sm) ((sm)->ptk)
  45. #define WPA_KEK(sm) ((sm)->ptk + 16)
  46. #endif