Annotation of embedaddon/strongswan/src/libimcv/plugins/imc_swima/imc_swima_state.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2017 Andreas Steffen
                      3:  * HSR Hochschule fuer Technik Rapperswil
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: #include "imc_swima_state.h"
                     17: 
                     18: #include <tncif_names.h>
                     19: 
                     20: #include <utils/debug.h>
                     21: 
                     22: typedef struct private_imc_swima_state_t private_imc_swima_state_t;
                     23: 
                     24: /**
                     25:  * Private data of an imc_swima_state_t object.
                     26:  */
                     27: struct private_imc_swima_state_t {
                     28: 
                     29:        /**
                     30:         * Public members of imc_swima_state_t
                     31:         */
                     32:        imc_swima_state_t public;
                     33: 
                     34:        /**
                     35:         * TNCCS connection ID
                     36:         */
                     37:        TNC_ConnectionID connection_id;
                     38: 
                     39:        /**
                     40:         * TNCCS connection state
                     41:         */
                     42:        TNC_ConnectionState state;
                     43: 
                     44:        /**
                     45:         * Assessment/Evaluation Result
                     46:         */
                     47:        TNC_IMV_Evaluation_Result result;
                     48: 
                     49:        /**
                     50:         * Does the TNCCS connection support long message types?
                     51:         */
                     52:        bool has_long;
                     53: 
                     54:        /**
                     55:         * Does the TNCCS connection support exclusive delivery?
                     56:         */
                     57:        bool has_excl;
                     58: 
                     59:        /**
                     60:         * Maximum PA-TNC message size for this TNCCS connection
                     61:         */
                     62:        uint32_t max_msg_len;
                     63: 
                     64:        /**
                     65:         * PA-TNC attribute segmentation contracts associated with TNCCS connection
                     66:         */
                     67:        seg_contract_manager_t *contracts;
                     68: 
                     69:        /**
                     70:         * Has a subscription been established?
                     71:         */
                     72:        bool has_subscription;
                     73: 
                     74:        /**
                     75:         * State information on subscriptions
                     76:         */
                     77:        imc_swima_subscription_t *subscription;
                     78: 
                     79:        /**
                     80:         * Earliest EID for the next subscription round
                     81:         */
                     82:        uint32_t earliest_eid;
                     83: 
                     84: };
                     85: 
                     86: static void free_subscription(imc_swima_subscription_t *this)
                     87: {
                     88:        if (this)
                     89:        {
                     90:                this->targets->destroy(this->targets);
                     91:                free(this);
                     92:        }
                     93: }
                     94: 
                     95: METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
                     96:        private_imc_swima_state_t *this)
                     97: {
                     98:        return this->connection_id;
                     99: }
                    100: 
                    101: METHOD(imc_state_t, has_long, bool,
                    102:        private_imc_swima_state_t *this)
                    103: {
                    104:        return this->has_long;
                    105: }
                    106: 
                    107: METHOD(imc_state_t, has_excl, bool,
                    108:        private_imc_swima_state_t *this)
                    109: {
                    110:        return this->has_excl;
                    111: }
                    112: 
                    113: METHOD(imc_state_t, set_flags, void,
                    114:        private_imc_swima_state_t *this, bool has_long, bool has_excl)
                    115: {
                    116:        this->has_long = has_long;
                    117:        this->has_excl = has_excl;
                    118: }
                    119: 
                    120: METHOD(imc_state_t, set_max_msg_len, void,
                    121:        private_imc_swima_state_t *this, uint32_t max_msg_len)
                    122: {
                    123:        this->max_msg_len = max_msg_len;
                    124: }
                    125: 
                    126: METHOD(imc_state_t, get_max_msg_len, uint32_t,
                    127:        private_imc_swima_state_t *this)
                    128: {
                    129:        return this->max_msg_len;
                    130: }
                    131: 
                    132: METHOD(imc_state_t, get_contracts, seg_contract_manager_t*,
                    133:        private_imc_swima_state_t *this)
                    134: {
                    135:        return this->contracts;
                    136: }
                    137: 
                    138: METHOD(imc_state_t, change_state, TNC_ConnectionState,
                    139:        private_imc_swima_state_t *this, TNC_ConnectionState new_state)
                    140: {
                    141:        TNC_ConnectionState old_state;
                    142: 
                    143:        old_state = this->state;
                    144:        this->state = new_state;
                    145:        return old_state;
                    146: }
                    147: 
                    148: METHOD(imc_state_t, set_result, void,
                    149:        private_imc_swima_state_t *this, TNC_IMCID id,
                    150:        TNC_IMV_Evaluation_Result result)
                    151: {
                    152:        this->result = result;
                    153: }
                    154: 
                    155: METHOD(imc_state_t, get_result, bool,
                    156:        private_imc_swima_state_t *this, TNC_IMCID id,
                    157:        TNC_IMV_Evaluation_Result *result)
                    158: {
                    159:        if (result)
                    160:        {
                    161:                *result = this->result;
                    162:        }
                    163:        return this->result != TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
                    164: }
                    165: 
                    166: METHOD(imc_state_t, reset, void,
                    167:        private_imc_swima_state_t *this)
                    168: {
                    169:        this->result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW;
                    170: }
                    171: 
                    172: METHOD(imc_state_t, destroy, void,
                    173:        private_imc_swima_state_t *this)
                    174: {
                    175:        free(this->subscription);
                    176:        this->contracts->destroy(this->contracts);
                    177:        free(this);
                    178: }
                    179: 
                    180: METHOD(imc_swima_state_t, set_subscription, void,
                    181:        private_imc_swima_state_t *this, imc_swima_subscription_t *subscription,
                    182:        bool set)
                    183: {
                    184:        free_subscription(this->subscription);
                    185:        this->has_subscription = set;
                    186: 
                    187:        if (set)
                    188:        {
                    189:                this->subscription = subscription;
                    190:        }
                    191:        else
                    192:        {
                    193:                this->subscription = NULL;
                    194:        }
                    195: }
                    196: 
                    197: METHOD(imc_swima_state_t, get_subscription, bool,
                    198:        private_imc_swima_state_t *this, imc_swima_subscription_t **subscription)
                    199: {
                    200:        if (subscription)
                    201:        {
                    202:                *subscription = this->subscription;
                    203:        }
                    204:        return this->has_subscription;
                    205: }
                    206: 
                    207: METHOD(imc_swima_state_t, set_earliest_eid, void,
                    208:        private_imc_swima_state_t *this, uint32_t eid)
                    209: {
                    210:        this->earliest_eid = eid;
                    211: }
                    212: 
                    213: METHOD(imc_swima_state_t, get_earliest_eid, uint32_t,
                    214:        private_imc_swima_state_t *this)
                    215: {
                    216:        return this->earliest_eid;
                    217: }
                    218: 
                    219: /**
                    220:  * Described in header.
                    221:  */
                    222: imc_state_t *imc_swima_state_create(TNC_ConnectionID connection_id)
                    223: {
                    224:        private_imc_swima_state_t *this;
                    225: 
                    226:        INIT(this,
                    227:                .public = {
                    228:                        .interface = {
                    229:                                .get_connection_id = _get_connection_id,
                    230:                                .has_long = _has_long,
                    231:                                .has_excl = _has_excl,
                    232:                                .set_flags = _set_flags,
                    233:                                .set_max_msg_len = _set_max_msg_len,
                    234:                                .get_max_msg_len = _get_max_msg_len,
                    235:                                .get_contracts = _get_contracts,
                    236:                                .change_state = _change_state,
                    237:                                .set_result = _set_result,
                    238:                                .get_result = _get_result,
                    239:                                .reset = _reset,
                    240:                                .destroy = _destroy,
                    241:                        },
                    242:                        .set_subscription = _set_subscription,
                    243:                        .get_subscription = _get_subscription,
                    244:                        .set_earliest_eid = _set_earliest_eid,
                    245:                        .get_earliest_eid = _get_earliest_eid,
                    246:                },
                    247:                .state = TNC_CONNECTION_STATE_CREATE,
                    248:                .result = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
                    249:                .connection_id = connection_id,
                    250:                .contracts = seg_contract_manager_create(),
                    251:        );
                    252: 
                    253:        return &this->public.interface;
                    254: }
                    255: 
                    256: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>