ieee802_1x_secy_ops.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /*
  2. * SecY Operations
  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. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/defs.h"
  12. #include "drivers/driver.h"
  13. #include "pae/ieee802_1x_kay.h"
  14. #include "pae/ieee802_1x_kay_i.h"
  15. #include "pae/ieee802_1x_secy_ops.h"
  16. int secy_cp_control_validate_frames(struct ieee802_1x_kay *kay,
  17. enum validate_frames vf)
  18. {
  19. kay->vf = vf;
  20. return 0;
  21. }
  22. int secy_cp_control_protect_frames(struct ieee802_1x_kay *kay, Boolean enabled)
  23. {
  24. struct ieee802_1x_kay_ctx *ops;
  25. if (!kay) {
  26. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  27. return -1;
  28. }
  29. ops = kay->ctx;
  30. if (!ops || !ops->enable_protect_frames) {
  31. wpa_printf(MSG_ERROR,
  32. "KaY: secy enable_protect_frames operation not supported");
  33. return -1;
  34. }
  35. return ops->enable_protect_frames(ops->ctx, enabled);
  36. }
  37. int secy_cp_control_replay(struct ieee802_1x_kay *kay, Boolean enabled, u32 win)
  38. {
  39. struct ieee802_1x_kay_ctx *ops;
  40. if (!kay) {
  41. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  42. return -1;
  43. }
  44. ops = kay->ctx;
  45. if (!ops || !ops->set_replay_protect) {
  46. wpa_printf(MSG_ERROR,
  47. "KaY: secy set_replay_protect operation not supported");
  48. return -1;
  49. }
  50. return ops->set_replay_protect(ops->ctx, enabled, win);
  51. }
  52. int secy_cp_control_current_cipher_suite(struct ieee802_1x_kay *kay, u64 cs)
  53. {
  54. struct ieee802_1x_kay_ctx *ops;
  55. if (!kay) {
  56. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  57. return -1;
  58. }
  59. ops = kay->ctx;
  60. if (!ops || !ops->set_current_cipher_suite) {
  61. wpa_printf(MSG_ERROR,
  62. "KaY: secy set_current_cipher_suite operation not supported");
  63. return -1;
  64. }
  65. return ops->set_current_cipher_suite(ops->ctx, cs);
  66. }
  67. int secy_cp_control_confidentiality_offset(struct ieee802_1x_kay *kay,
  68. enum confidentiality_offset co)
  69. {
  70. kay->co = co;
  71. return 0;
  72. }
  73. int secy_cp_control_enable_port(struct ieee802_1x_kay *kay, Boolean enabled)
  74. {
  75. struct ieee802_1x_kay_ctx *ops;
  76. if (!kay) {
  77. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  78. return -1;
  79. }
  80. ops = kay->ctx;
  81. if (!ops || !ops->enable_controlled_port) {
  82. wpa_printf(MSG_ERROR,
  83. "KaY: secy enable_controlled_port operation not supported");
  84. return -1;
  85. }
  86. return ops->enable_controlled_port(ops->ctx, enabled);
  87. }
  88. int secy_get_receive_lowest_pn(struct ieee802_1x_kay *kay,
  89. struct receive_sa *rxsa)
  90. {
  91. struct ieee802_1x_kay_ctx *ops;
  92. if (!kay || !rxsa) {
  93. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  94. return -1;
  95. }
  96. ops = kay->ctx;
  97. if (!ops || !ops->get_receive_lowest_pn) {
  98. wpa_printf(MSG_ERROR,
  99. "KaY: secy get_receive_lowest_pn operation not supported");
  100. return -1;
  101. }
  102. return ops->get_receive_lowest_pn(ops->ctx, rxsa);
  103. }
  104. int secy_get_transmit_next_pn(struct ieee802_1x_kay *kay,
  105. struct transmit_sa *txsa)
  106. {
  107. struct ieee802_1x_kay_ctx *ops;
  108. if (!kay || !txsa) {
  109. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  110. return -1;
  111. }
  112. ops = kay->ctx;
  113. if (!ops || !ops->get_transmit_next_pn) {
  114. wpa_printf(MSG_ERROR,
  115. "KaY: secy get_receive_lowest_pn operation not supported");
  116. return -1;
  117. }
  118. return ops->get_transmit_next_pn(ops->ctx, txsa);
  119. }
  120. int secy_set_transmit_next_pn(struct ieee802_1x_kay *kay,
  121. struct transmit_sa *txsa)
  122. {
  123. struct ieee802_1x_kay_ctx *ops;
  124. if (!kay || !txsa) {
  125. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  126. return -1;
  127. }
  128. ops = kay->ctx;
  129. if (!ops || !ops->set_transmit_next_pn) {
  130. wpa_printf(MSG_ERROR,
  131. "KaY: secy get_receive_lowest_pn operation not supported");
  132. return -1;
  133. }
  134. return ops->set_transmit_next_pn(ops->ctx, txsa);
  135. }
  136. int secy_get_available_receive_sc(struct ieee802_1x_kay *kay, u32 *channel)
  137. {
  138. struct ieee802_1x_kay_ctx *ops;
  139. if (!kay) {
  140. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  141. return -1;
  142. }
  143. ops = kay->ctx;
  144. if (!ops || !ops->get_available_receive_sc) {
  145. wpa_printf(MSG_ERROR,
  146. "KaY: secy get_available_receive_sc operation not supported");
  147. return -1;
  148. }
  149. return ops->get_available_receive_sc(ops->ctx, channel);
  150. }
  151. int secy_create_receive_sc(struct ieee802_1x_kay *kay, struct receive_sc *rxsc)
  152. {
  153. struct ieee802_1x_kay_ctx *ops;
  154. if (!kay || !rxsc) {
  155. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  156. return -1;
  157. }
  158. ops = kay->ctx;
  159. if (!ops || !ops->create_receive_sc) {
  160. wpa_printf(MSG_ERROR,
  161. "KaY: secy create_receive_sc operation not supported");
  162. return -1;
  163. }
  164. return ops->create_receive_sc(ops->ctx, rxsc->channel, &rxsc->sci,
  165. kay->vf, kay->co);
  166. }
  167. int secy_delete_receive_sc(struct ieee802_1x_kay *kay, struct receive_sc *rxsc)
  168. {
  169. struct ieee802_1x_kay_ctx *ops;
  170. if (!kay || !rxsc) {
  171. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  172. return -1;
  173. }
  174. ops = kay->ctx;
  175. if (!ops || !ops->delete_receive_sc) {
  176. wpa_printf(MSG_ERROR,
  177. "KaY: secy delete_receive_sc operation not supported");
  178. return -1;
  179. }
  180. return ops->delete_receive_sc(ops->ctx, rxsc->channel);
  181. }
  182. int secy_create_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
  183. {
  184. struct ieee802_1x_kay_ctx *ops;
  185. if (!kay || !rxsa) {
  186. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  187. return -1;
  188. }
  189. ops = kay->ctx;
  190. if (!ops || !ops->create_receive_sa) {
  191. wpa_printf(MSG_ERROR,
  192. "KaY: secy create_receive_sa operation not supported");
  193. return -1;
  194. }
  195. return ops->create_receive_sa(ops->ctx, rxsa);
  196. }
  197. int secy_enable_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
  198. {
  199. struct ieee802_1x_kay_ctx *ops;
  200. if (!kay || !rxsa) {
  201. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  202. return -1;
  203. }
  204. ops = kay->ctx;
  205. if (!ops || !ops->enable_receive_sa) {
  206. wpa_printf(MSG_ERROR,
  207. "KaY: secy enable_receive_sa operation not supported");
  208. return -1;
  209. }
  210. rxsa->enable_receive = TRUE;
  211. return ops->enable_receive_sa(ops->ctx, rxsa);
  212. }
  213. int secy_disable_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
  214. {
  215. struct ieee802_1x_kay_ctx *ops;
  216. if (!kay || !rxsa) {
  217. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  218. return -1;
  219. }
  220. ops = kay->ctx;
  221. if (!ops || !ops->disable_receive_sa) {
  222. wpa_printf(MSG_ERROR,
  223. "KaY: secy disable_receive_sa operation not supported");
  224. return -1;
  225. }
  226. rxsa->enable_receive = FALSE;
  227. return ops->disable_receive_sa(ops->ctx, rxsa);
  228. }
  229. int secy_get_available_transmit_sc(struct ieee802_1x_kay *kay, u32 *channel)
  230. {
  231. struct ieee802_1x_kay_ctx *ops;
  232. if (!kay) {
  233. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  234. return -1;
  235. }
  236. ops = kay->ctx;
  237. if (!ops || !ops->get_available_transmit_sc) {
  238. wpa_printf(MSG_ERROR,
  239. "KaY: secy get_available_transmit_sc operation not supported");
  240. return -1;
  241. }
  242. return ops->get_available_transmit_sc(ops->ctx, channel);
  243. }
  244. int secy_create_transmit_sc(struct ieee802_1x_kay *kay,
  245. struct transmit_sc *txsc)
  246. {
  247. struct ieee802_1x_kay_ctx *ops;
  248. if (!kay || !txsc) {
  249. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  250. return -1;
  251. }
  252. ops = kay->ctx;
  253. if (!ops || !ops->create_transmit_sc) {
  254. wpa_printf(MSG_ERROR,
  255. "KaY: secy create_transmit_sc operation not supported");
  256. return -1;
  257. }
  258. return ops->create_transmit_sc(ops->ctx, txsc->channel, &txsc->sci,
  259. kay->co);
  260. }
  261. int secy_delete_transmit_sc(struct ieee802_1x_kay *kay,
  262. struct transmit_sc *txsc)
  263. {
  264. struct ieee802_1x_kay_ctx *ops;
  265. if (!kay || !txsc) {
  266. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  267. return -1;
  268. }
  269. ops = kay->ctx;
  270. if (!ops || !ops->delete_transmit_sc) {
  271. wpa_printf(MSG_ERROR,
  272. "KaY: secy delete_transmit_sc operation not supported");
  273. return -1;
  274. }
  275. return ops->delete_transmit_sc(ops->ctx, txsc->channel);
  276. }
  277. int secy_create_transmit_sa(struct ieee802_1x_kay *kay,
  278. struct transmit_sa *txsa)
  279. {
  280. struct ieee802_1x_kay_ctx *ops;
  281. if (!kay || !txsa) {
  282. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  283. return -1;
  284. }
  285. ops = kay->ctx;
  286. if (!ops || !ops->create_transmit_sa) {
  287. wpa_printf(MSG_ERROR,
  288. "KaY: secy create_transmit_sa operation not supported");
  289. return -1;
  290. }
  291. return ops->create_transmit_sa(ops->ctx, txsa);
  292. }
  293. int secy_enable_transmit_sa(struct ieee802_1x_kay *kay,
  294. struct transmit_sa *txsa)
  295. {
  296. struct ieee802_1x_kay_ctx *ops;
  297. if (!kay || !txsa) {
  298. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  299. return -1;
  300. }
  301. ops = kay->ctx;
  302. if (!ops || !ops->enable_transmit_sa) {
  303. wpa_printf(MSG_ERROR,
  304. "KaY: secy enable_transmit_sa operation not supported");
  305. return -1;
  306. }
  307. txsa->enable_transmit = TRUE;
  308. return ops->enable_transmit_sa(ops->ctx, txsa);
  309. }
  310. int secy_disable_transmit_sa(struct ieee802_1x_kay *kay,
  311. struct transmit_sa *txsa)
  312. {
  313. struct ieee802_1x_kay_ctx *ops;
  314. if (!kay || !txsa) {
  315. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  316. return -1;
  317. }
  318. ops = kay->ctx;
  319. if (!ops || !ops->disable_transmit_sa) {
  320. wpa_printf(MSG_ERROR,
  321. "KaY: secy disable_transmit_sa operation not supported");
  322. return -1;
  323. }
  324. txsa->enable_transmit = FALSE;
  325. return ops->disable_transmit_sa(ops->ctx, txsa);
  326. }
  327. int secy_init_macsec(struct ieee802_1x_kay *kay)
  328. {
  329. int ret;
  330. struct ieee802_1x_kay_ctx *ops;
  331. struct macsec_init_params params;
  332. if (!kay) {
  333. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  334. return -1;
  335. }
  336. ops = kay->ctx;
  337. if (!ops || !ops->macsec_init) {
  338. wpa_printf(MSG_ERROR,
  339. "KaY: secy macsec_init operation not supported");
  340. return -1;
  341. }
  342. params.use_es = FALSE;
  343. params.use_scb = FALSE;
  344. params.always_include_sci = TRUE;
  345. ret = ops->macsec_init(ops->ctx, &params);
  346. return ret;
  347. }
  348. int secy_deinit_macsec(struct ieee802_1x_kay *kay)
  349. {
  350. struct ieee802_1x_kay_ctx *ops;
  351. if (!kay) {
  352. wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
  353. return -1;
  354. }
  355. ops = kay->ctx;
  356. if (!ops || !ops->macsec_deinit) {
  357. wpa_printf(MSG_ERROR,
  358. "KaY: secy macsec_deinit operation not supported");
  359. return -1;
  360. }
  361. return ops->macsec_deinit(ops->ctx);
  362. }