ieee802_1x_secy_ops.c 10 KB

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