ieee802_1x_kay.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * IEEE 802.1X-2010 Key Agree Protocol of PAE state machine
  3. * Copyright (c) 2013, Qualcomm Atheros, Inc.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef IEEE802_1X_KAY_H
  9. #define IEEE802_1X_KAY_H
  10. #include "utils/list.h"
  11. #include "common/defs.h"
  12. #include "common/ieee802_1x_defs.h"
  13. struct macsec_init_params;
  14. #define MI_LEN 12
  15. #define MAX_KEY_LEN 32 /* 32 bytes, 256 bits */
  16. #define MAX_CKN_LEN 32 /* 32 bytes, 256 bits */
  17. /* MKA timer, unit: millisecond */
  18. #define MKA_HELLO_TIME 2000
  19. #define MKA_LIFE_TIME 6000
  20. #define MKA_SAK_RETIRE_TIME 3000
  21. struct ieee802_1x_mka_ki {
  22. u8 mi[MI_LEN];
  23. u32 kn;
  24. };
  25. struct ieee802_1x_mka_sci {
  26. u8 addr[ETH_ALEN];
  27. be16 port;
  28. };
  29. struct mka_key {
  30. u8 key[MAX_KEY_LEN];
  31. size_t len;
  32. };
  33. struct mka_key_name {
  34. u8 name[MAX_CKN_LEN];
  35. size_t len;
  36. };
  37. enum mka_created_mode {
  38. PSK,
  39. EAP_EXCHANGE,
  40. };
  41. struct data_key {
  42. u8 *key;
  43. int key_len;
  44. struct ieee802_1x_mka_ki key_identifier;
  45. enum confidentiality_offset confidentiality_offset;
  46. u8 an;
  47. Boolean transmits;
  48. Boolean receives;
  49. struct os_time created_time;
  50. u32 next_pn;
  51. /* not defined data */
  52. Boolean rx_latest;
  53. Boolean tx_latest;
  54. int user; /* FIXME: to indicate if it can be delete safely */
  55. struct dl_list list;
  56. };
  57. /* TransmitSC in IEEE Std 802.1AE-2006, Figure 10-6 */
  58. struct transmit_sc {
  59. struct ieee802_1x_mka_sci sci; /* const SCI sci */
  60. Boolean transmitting; /* bool transmitting (read only) */
  61. struct os_time created_time; /* Time createdTime */
  62. u8 encoding_sa; /* AN encodingSA (read only) */
  63. u8 enciphering_sa; /* AN encipheringSA (read only) */
  64. /* not defined data */
  65. unsigned int channel;
  66. struct dl_list list;
  67. struct dl_list sa_list;
  68. };
  69. /* TransmitSA in IEEE Std 802.1AE-2006, Figure 10-6 */
  70. struct transmit_sa {
  71. Boolean in_use; /* bool inUse (read only) */
  72. u32 next_pn; /* PN nextPN (read only) */
  73. struct os_time created_time; /* Time createdTime */
  74. Boolean enable_transmit; /* bool EnableTransmit */
  75. u8 an;
  76. Boolean confidentiality;
  77. struct data_key *pkey;
  78. struct transmit_sc *sc;
  79. struct dl_list list; /* list entry in struct transmit_sc::sa_list */
  80. };
  81. /* ReceiveSC in IEEE Std 802.1AE-2006, Figure 10-6 */
  82. struct receive_sc {
  83. struct ieee802_1x_mka_sci sci; /* const SCI sci */
  84. Boolean receiving; /* bool receiving (read only) */
  85. struct os_time created_time; /* Time createdTime */
  86. unsigned int channel;
  87. struct dl_list list;
  88. struct dl_list sa_list;
  89. };
  90. /* ReceiveSA in IEEE Std 802.1AE-2006, Figure 10-6 */
  91. struct receive_sa {
  92. Boolean enable_receive; /* bool enableReceive */
  93. Boolean in_use; /* bool inUse (read only) */
  94. u32 next_pn; /* PN nextPN (read only) */
  95. u32 lowest_pn; /* PN lowestPN (read only) */
  96. u8 an;
  97. struct os_time created_time;
  98. struct data_key *pkey;
  99. struct receive_sc *sc; /* list entry in struct receive_sc::sa_list */
  100. struct dl_list list;
  101. };
  102. struct ieee802_1x_kay_ctx {
  103. /* pointer to arbitrary upper level context */
  104. void *ctx;
  105. /* abstract wpa driver interface */
  106. int (*macsec_init)(void *ctx, struct macsec_init_params *params);
  107. int (*macsec_deinit)(void *ctx);
  108. int (*macsec_get_capability)(void *priv, enum macsec_cap *cap);
  109. int (*enable_protect_frames)(void *ctx, Boolean enabled);
  110. int (*set_replay_protect)(void *ctx, Boolean enabled, u32 window);
  111. int (*set_current_cipher_suite)(void *ctx, u64 cs);
  112. int (*enable_controlled_port)(void *ctx, Boolean enabled);
  113. int (*get_receive_lowest_pn)(void *ctx, struct receive_sa *sa);
  114. int (*get_transmit_next_pn)(void *ctx, struct transmit_sa *sa);
  115. int (*set_transmit_next_pn)(void *ctx, struct transmit_sa *sa);
  116. int (*get_available_receive_sc)(void *ctx, u32 *channel);
  117. int (*create_receive_sc)(void *ctx, struct receive_sc *sc,
  118. enum validate_frames vf,
  119. enum confidentiality_offset co);
  120. int (*delete_receive_sc)(void *ctx, struct receive_sc *sc);
  121. int (*create_receive_sa)(void *ctx, struct receive_sa *sa);
  122. int (*enable_receive_sa)(void *ctx, struct receive_sa *sa);
  123. int (*disable_receive_sa)(void *ctx, struct receive_sa *sa);
  124. int (*get_available_transmit_sc)(void *ctx, u32 *channel);
  125. int (*create_transmit_sc)(void *ctx, struct transmit_sc *sc,
  126. enum confidentiality_offset co);
  127. int (*delete_transmit_sc)(void *ctx, struct transmit_sc *sc);
  128. int (*create_transmit_sa)(void *ctx, struct transmit_sa *sa);
  129. int (*enable_transmit_sa)(void *ctx, struct transmit_sa *sa);
  130. int (*disable_transmit_sa)(void *ctx, struct transmit_sa *sa);
  131. };
  132. struct ieee802_1x_kay {
  133. Boolean enable;
  134. Boolean active;
  135. Boolean authenticated;
  136. Boolean secured;
  137. Boolean failed;
  138. struct ieee802_1x_mka_sci actor_sci;
  139. u8 actor_priority;
  140. struct ieee802_1x_mka_sci key_server_sci;
  141. u8 key_server_priority;
  142. enum macsec_cap macsec_capable;
  143. Boolean macsec_desired;
  144. Boolean macsec_protect;
  145. Boolean macsec_replay_protect;
  146. u32 macsec_replay_window;
  147. enum validate_frames macsec_validate;
  148. enum confidentiality_offset macsec_confidentiality;
  149. u32 ltx_kn;
  150. u8 ltx_an;
  151. u32 lrx_kn;
  152. u8 lrx_an;
  153. u32 otx_kn;
  154. u8 otx_an;
  155. u32 orx_kn;
  156. u8 orx_an;
  157. /* not defined in IEEE802.1X */
  158. struct ieee802_1x_kay_ctx *ctx;
  159. Boolean is_key_server;
  160. Boolean is_obliged_key_server;
  161. char if_name[IFNAMSIZ];
  162. unsigned int macsec_csindex; /* MACsec cipher suite table index */
  163. int mka_algindex; /* MKA alg table index */
  164. u32 dist_kn;
  165. u8 dist_an;
  166. time_t dist_time;
  167. u8 mka_version;
  168. u8 algo_agility[4];
  169. u32 sc_ch;
  170. u32 pn_exhaustion;
  171. Boolean port_enable;
  172. Boolean rx_enable;
  173. Boolean tx_enable;
  174. struct dl_list participant_list;
  175. enum macsec_policy policy;
  176. struct ieee802_1x_cp_sm *cp;
  177. struct l2_packet_data *l2_mka;
  178. enum validate_frames vf;
  179. enum confidentiality_offset co;
  180. };
  181. struct ieee802_1x_kay *
  182. ieee802_1x_kay_init(struct ieee802_1x_kay_ctx *ctx, enum macsec_policy policy,
  183. const char *ifname, const u8 *addr);
  184. void ieee802_1x_kay_deinit(struct ieee802_1x_kay *kay);
  185. struct ieee802_1x_mka_participant *
  186. ieee802_1x_kay_create_mka(struct ieee802_1x_kay *kay,
  187. struct mka_key_name *ckn, struct mka_key *cak,
  188. u32 life, enum mka_created_mode mode,
  189. Boolean is_authenticator);
  190. void ieee802_1x_kay_delete_mka(struct ieee802_1x_kay *kay,
  191. struct mka_key_name *ckn);
  192. void ieee802_1x_kay_mka_participate(struct ieee802_1x_kay *kay,
  193. struct mka_key_name *ckn,
  194. Boolean status);
  195. int ieee802_1x_kay_new_sak(struct ieee802_1x_kay *kay);
  196. int ieee802_1x_kay_change_cipher_suite(struct ieee802_1x_kay *kay,
  197. unsigned int cs_index);
  198. int ieee802_1x_kay_set_latest_sa_attr(struct ieee802_1x_kay *kay,
  199. struct ieee802_1x_mka_ki *lki, u8 lan,
  200. Boolean ltx, Boolean lrx);
  201. int ieee802_1x_kay_set_old_sa_attr(struct ieee802_1x_kay *kay,
  202. struct ieee802_1x_mka_ki *oki,
  203. u8 oan, Boolean otx, Boolean orx);
  204. int ieee802_1x_kay_create_sas(struct ieee802_1x_kay *kay,
  205. struct ieee802_1x_mka_ki *lki);
  206. int ieee802_1x_kay_delete_sas(struct ieee802_1x_kay *kay,
  207. struct ieee802_1x_mka_ki *ki);
  208. int ieee802_1x_kay_enable_tx_sas(struct ieee802_1x_kay *kay,
  209. struct ieee802_1x_mka_ki *lki);
  210. int ieee802_1x_kay_enable_rx_sas(struct ieee802_1x_kay *kay,
  211. struct ieee802_1x_mka_ki *lki);
  212. int ieee802_1x_kay_enable_new_info(struct ieee802_1x_kay *kay);
  213. #endif /* IEEE802_1X_KAY_H */