123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- /*
- * SecY Operations
- * Copyright (c) 2013, Qualcomm Atheros, Inc.
- *
- * This software may be distributed under the terms of the BSD license.
- * See README for more details.
- */
- #include "utils/includes.h"
- #include "utils/common.h"
- #include "utils/eloop.h"
- #include "common/defs.h"
- #include "drivers/driver.h"
- #include "pae/ieee802_1x_kay.h"
- #include "pae/ieee802_1x_kay_i.h"
- #include "pae/ieee802_1x_secy_ops.h"
- int secy_cp_control_validate_frames(struct ieee802_1x_kay *kay,
- enum validate_frames vf)
- {
- kay->vf = vf;
- return 0;
- }
- int secy_cp_control_protect_frames(struct ieee802_1x_kay *kay, Boolean enabled)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->enable_protect_frames) {
- wpa_printf(MSG_ERROR,
- "KaY: secy enable_protect_frames operation not supported");
- return -1;
- }
- return ops->enable_protect_frames(ops->ctx, enabled);
- }
- int secy_cp_control_replay(struct ieee802_1x_kay *kay, Boolean enabled, u32 win)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->set_replay_protect) {
- wpa_printf(MSG_ERROR,
- "KaY: secy set_replay_protect operation not supported");
- return -1;
- }
- return ops->set_replay_protect(ops->ctx, enabled, win);
- }
- int secy_cp_control_current_cipher_suite(struct ieee802_1x_kay *kay,
- const u8 *cs, size_t cs_len)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->set_current_cipher_suite) {
- wpa_printf(MSG_ERROR,
- "KaY: secy set_current_cipher_suite operation not supported");
- return -1;
- }
- return ops->set_current_cipher_suite(ops->ctx, cs, cs_len);
- }
- int secy_cp_control_confidentiality_offset(struct ieee802_1x_kay *kay,
- enum confidentiality_offset co)
- {
- kay->co = co;
- return 0;
- }
- int secy_cp_control_enable_port(struct ieee802_1x_kay *kay, Boolean enabled)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->enable_controlled_port) {
- wpa_printf(MSG_ERROR,
- "KaY: secy enable_controlled_port operation not supported");
- return -1;
- }
- return ops->enable_controlled_port(ops->ctx, enabled);
- }
- int secy_get_receive_lowest_pn(struct ieee802_1x_kay *kay,
- struct receive_sa *rxsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->get_receive_lowest_pn) {
- wpa_printf(MSG_ERROR,
- "KaY: secy get_receive_lowest_pn operation not supported");
- return -1;
- }
- return ops->get_receive_lowest_pn(ops->ctx,
- rxsa->sc->channel,
- rxsa->an,
- &rxsa->lowest_pn);
- }
- int secy_get_transmit_next_pn(struct ieee802_1x_kay *kay,
- struct transmit_sa *txsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->get_transmit_next_pn) {
- wpa_printf(MSG_ERROR,
- "KaY: secy get_receive_lowest_pn operation not supported");
- return -1;
- }
- return ops->get_transmit_next_pn(ops->ctx,
- txsa->sc->channel,
- txsa->an,
- &txsa->next_pn);
- }
- int secy_set_transmit_next_pn(struct ieee802_1x_kay *kay,
- struct transmit_sa *txsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->set_transmit_next_pn) {
- wpa_printf(MSG_ERROR,
- "KaY: secy get_receive_lowest_pn operation not supported");
- return -1;
- }
- return ops->set_transmit_next_pn(ops->ctx,
- txsa->sc->channel,
- txsa->an,
- txsa->next_pn);
- }
- int secy_get_available_receive_sc(struct ieee802_1x_kay *kay, u32 *channel)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->get_available_receive_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy get_available_receive_sc operation not supported");
- return -1;
- }
- return ops->get_available_receive_sc(ops->ctx, channel);
- }
- int secy_create_receive_sc(struct ieee802_1x_kay *kay, struct receive_sc *rxsc)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsc) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->create_receive_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy create_receive_sc operation not supported");
- return -1;
- }
- return ops->create_receive_sc(ops->ctx, rxsc->channel, &rxsc->sci,
- kay->vf, kay->co);
- }
- int secy_delete_receive_sc(struct ieee802_1x_kay *kay, struct receive_sc *rxsc)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsc) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->delete_receive_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy delete_receive_sc operation not supported");
- return -1;
- }
- return ops->delete_receive_sc(ops->ctx, rxsc->channel);
- }
- int secy_create_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->create_receive_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy create_receive_sa operation not supported");
- return -1;
- }
- return ops->create_receive_sa(ops->ctx, rxsa->sc->channel, rxsa->an,
- rxsa->lowest_pn, rxsa->pkey->key);
- }
- int secy_enable_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->enable_receive_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy enable_receive_sa operation not supported");
- return -1;
- }
- rxsa->enable_receive = TRUE;
- return ops->enable_receive_sa(ops->ctx, rxsa->sc->channel, rxsa->an);
- }
- int secy_disable_receive_sa(struct ieee802_1x_kay *kay, struct receive_sa *rxsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !rxsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->disable_receive_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy disable_receive_sa operation not supported");
- return -1;
- }
- rxsa->enable_receive = FALSE;
- return ops->disable_receive_sa(ops->ctx, rxsa->sc->channel, rxsa->an);
- }
- int secy_get_available_transmit_sc(struct ieee802_1x_kay *kay, u32 *channel)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->get_available_transmit_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy get_available_transmit_sc operation not supported");
- return -1;
- }
- return ops->get_available_transmit_sc(ops->ctx, channel);
- }
- int secy_create_transmit_sc(struct ieee802_1x_kay *kay,
- struct transmit_sc *txsc)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsc) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->create_transmit_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy create_transmit_sc operation not supported");
- return -1;
- }
- return ops->create_transmit_sc(ops->ctx, txsc->channel, &txsc->sci,
- kay->co);
- }
- int secy_delete_transmit_sc(struct ieee802_1x_kay *kay,
- struct transmit_sc *txsc)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsc) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->delete_transmit_sc) {
- wpa_printf(MSG_ERROR,
- "KaY: secy delete_transmit_sc operation not supported");
- return -1;
- }
- return ops->delete_transmit_sc(ops->ctx, txsc->channel);
- }
- int secy_create_transmit_sa(struct ieee802_1x_kay *kay,
- struct transmit_sa *txsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->create_transmit_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy create_transmit_sa operation not supported");
- return -1;
- }
- return ops->create_transmit_sa(ops->ctx, txsa->sc->channel, txsa->an,
- txsa->next_pn, txsa->confidentiality,
- txsa->pkey->key);
- }
- int secy_enable_transmit_sa(struct ieee802_1x_kay *kay,
- struct transmit_sa *txsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->enable_transmit_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy enable_transmit_sa operation not supported");
- return -1;
- }
- txsa->enable_transmit = TRUE;
- return ops->enable_transmit_sa(ops->ctx, txsa->sc->channel, txsa->an);
- }
- int secy_disable_transmit_sa(struct ieee802_1x_kay *kay,
- struct transmit_sa *txsa)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay || !txsa) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->disable_transmit_sa) {
- wpa_printf(MSG_ERROR,
- "KaY: secy disable_transmit_sa operation not supported");
- return -1;
- }
- txsa->enable_transmit = FALSE;
- return ops->disable_transmit_sa(ops->ctx, txsa->sc->channel, txsa->an);
- }
- int secy_init_macsec(struct ieee802_1x_kay *kay)
- {
- int ret;
- struct ieee802_1x_kay_ctx *ops;
- struct macsec_init_params params;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->macsec_init) {
- wpa_printf(MSG_ERROR,
- "KaY: secy macsec_init operation not supported");
- return -1;
- }
- params.use_es = FALSE;
- params.use_scb = FALSE;
- params.always_include_sci = TRUE;
- ret = ops->macsec_init(ops->ctx, ¶ms);
- return ret;
- }
- int secy_deinit_macsec(struct ieee802_1x_kay *kay)
- {
- struct ieee802_1x_kay_ctx *ops;
- if (!kay) {
- wpa_printf(MSG_ERROR, "KaY: %s params invalid", __func__);
- return -1;
- }
- ops = kay->ctx;
- if (!ops || !ops->macsec_deinit) {
- wpa_printf(MSG_ERROR,
- "KaY: secy macsec_deinit operation not supported");
- return -1;
- }
- return ops->macsec_deinit(ops->ctx);
- }
|