Annotation of embedaddon/strongswan/src/libimcv/plugins/imc_hcd/imc_hcd.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2015 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_hcd_state.h"
        !            17: 
        !            18: #include <imc/imc_agent.h>
        !            19: #include <imc/imc_msg.h>
        !            20: #include <imc/imc_os_info.h>
        !            21: #include <generic/generic_attr_bool.h>
        !            22: #include <generic/generic_attr_chunk.h>
        !            23: #include <generic/generic_attr_string.h>
        !            24: #include <ietf/ietf_attr.h>
        !            25: #include <ietf/ietf_attr_attr_request.h>
        !            26: #include "ietf/ietf_attr_fwd_enabled.h"
        !            27: #include <pwg/pwg_attr.h>
        !            28: #include <pwg/pwg_attr_vendor_smi_code.h>
        !            29: 
        !            30: #include <tncif_pa_subtypes.h>
        !            31: 
        !            32: #include <pen/pen.h>
        !            33: #include <utils/debug.h>
        !            34: 
        !            35: /* IMC definitions */
        !            36: 
        !            37: static const char imc_name[] = "HCD";
        !            38: 
        !            39: static pen_type_t msg_types[] = {
        !            40:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_SYSTEM },
        !            41:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_CONSOLE },
        !            42:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_MARKER },
        !            43:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_FINISHER },
        !            44:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_INTERFACE },
        !            45:        { PEN_PWG, PA_SUBTYPE_PWG_HCD_SCANNER }
        !            46: };
        !            47: 
        !            48: static imc_agent_t *imc_hcd;
        !            49: static imc_os_info_t *os;
        !            50: 
        !            51: typedef struct section_subtype_t section_subtype_t;
        !            52: 
        !            53: struct section_subtype_t {
        !            54:        char *section;
        !            55:        pa_subtype_pwg_t subtype;
        !            56: };
        !            57: 
        !            58: static section_subtype_t section_subtypes[] = {
        !            59:        { "system",    PA_SUBTYPE_PWG_HCD_SYSTEM    },
        !            60:        { "console",   PA_SUBTYPE_PWG_HCD_CONSOLE   },
        !            61:        { "marker",    PA_SUBTYPE_PWG_HCD_MARKER    },
        !            62:        { "finisher",  PA_SUBTYPE_PWG_HCD_FINISHER  },
        !            63:        { "interface", PA_SUBTYPE_PWG_HCD_INTERFACE },
        !            64:        { "scanner"  , PA_SUBTYPE_PWG_HCD_SCANNER   }
        !            65: };
        !            66: 
        !            67: typedef struct quadruple_t quadruple_t;
        !            68: 
        !            69: struct quadruple_t {
        !            70:        char *section;
        !            71:        pwg_attr_t name_attr;
        !            72:        pwg_attr_t patches_attr;
        !            73:        pwg_attr_t string_version_attr;
        !            74:        pwg_attr_t version_attr;
        !            75: };
        !            76: 
        !            77: static quadruple_t quadruples[] = {
        !            78:        { "firmware",
        !            79:           PWG_HCD_FIRMWARE_NAME, PWG_HCD_FIRMWARE_PATCHES,
        !            80:           PWG_HCD_FIRMWARE_STRING_VERSION, PWG_HCD_FIRMWARE_VERSION },
        !            81:        { "resident_application",
        !            82:           PWG_HCD_RESIDENT_APP_NAME, PWG_HCD_RESIDENT_APP_PATCHES,
        !            83:           PWG_HCD_RESIDENT_APP_STRING_VERSION, PWG_HCD_RESIDENT_APP_VERSION },
        !            84:        { "user_application",
        !            85:           PWG_HCD_USER_APP_NAME, PWG_HCD_USER_APP_PATCHES,
        !            86:           PWG_HCD_USER_APP_STRING_VERSION, PWG_HCD_USER_APP_VERSION }
        !            87: };
        !            88: 
        !            89: /**
        !            90:  * see section 3.8.1 of TCG TNC IF-IMC Specification 1.3
        !            91:  */
        !            92: TNC_Result TNC_IMC_API TNC_IMC_Initialize(TNC_IMCID imc_id,
        !            93:                                                                                  TNC_Version min_version,
        !            94:                                                                                  TNC_Version max_version,
        !            95:                                                                                  TNC_Version *actual_version)
        !            96: {
        !            97:        if (imc_hcd)
        !            98:        {
        !            99:                DBG1(DBG_IMC, "IMC \"%s\" has already been initialized", imc_name);
        !           100:                return TNC_RESULT_ALREADY_INITIALIZED;
        !           101:        }
        !           102:        imc_hcd = imc_agent_create(imc_name, msg_types, countof(msg_types),
        !           103:                                                          imc_id, actual_version);
        !           104:        if (!imc_hcd)
        !           105:        {
        !           106:                return TNC_RESULT_FATAL;
        !           107:        }
        !           108: 
        !           109:        os = imc_os_info_create();
        !           110:        if (!os)
        !           111:        {
        !           112:                imc_hcd->destroy(imc_hcd);
        !           113:                imc_hcd = NULL;
        !           114: 
        !           115:                return TNC_RESULT_FATAL;
        !           116:        }
        !           117: 
        !           118:        if (min_version > TNC_IFIMC_VERSION_1 || max_version < TNC_IFIMC_VERSION_1)
        !           119:        {
        !           120:                DBG1(DBG_IMC, "no common IF-IMC version");
        !           121:                return TNC_RESULT_NO_COMMON_VERSION;
        !           122:        }
        !           123:        return TNC_RESULT_SUCCESS;
        !           124: }
        !           125: 
        !           126: /**
        !           127:  * see section 3.8.2 of TCG TNC IF-IMC Specification 1.3
        !           128:  */
        !           129: TNC_Result TNC_IMC_API TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
        !           130:                                TNC_ConnectionID connection_id, TNC_ConnectionState new_state)
        !           131: {
        !           132:        imc_state_t *state;
        !           133: 
        !           134:        if (!imc_hcd)
        !           135:        {
        !           136:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           137:                return TNC_RESULT_NOT_INITIALIZED;
        !           138:        }
        !           139:        switch (new_state)
        !           140:        {
        !           141:                case TNC_CONNECTION_STATE_CREATE:
        !           142:                        state = imc_hcd_state_create(connection_id);
        !           143:                        return imc_hcd->create_state(imc_hcd, state);
        !           144:                case TNC_CONNECTION_STATE_DELETE:
        !           145:                        return imc_hcd->delete_state(imc_hcd, connection_id);
        !           146:                default:
        !           147:                        return imc_hcd->change_state(imc_hcd, connection_id,
        !           148:                                                                                         new_state, NULL);
        !           149:        }
        !           150: }
        !           151: 
        !           152: /**
        !           153:  * Add AttributesNaturalLanguage attribute to send queue
        !           154:  */
        !           155: static void add_attrs_natural_lang(imc_msg_t *msg, char *section)
        !           156: {
        !           157:        pa_tnc_attr_t *attr;
        !           158:        char *string;
        !           159: 
        !           160:        string = lib->settings->get_str(lib->settings,
        !           161:                                "%s.plugins.imc-hcd.subtypes.%s.attributes_natural_language",
        !           162:                                "en", lib->ns, section);
        !           163:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_ATTRS_NATURAL_LANG,
        !           164:                                string);
        !           165:        attr = generic_attr_string_create(chunk_from_str(string),
        !           166:                                pen_type_create(PEN_PWG, PWG_HCD_ATTRS_NATURAL_LANG));
        !           167:        msg->add_attribute(msg, attr);
        !           168: }
        !           169: 
        !           170: /**
        !           171:  * Add DefaultPasswordEnabled attribute to send queue
        !           172:  */
        !           173: static void add_default_pwd_enabled(imc_msg_t *msg)
        !           174: {
        !           175:        pa_tnc_attr_t *attr;
        !           176:        bool status;
        !           177: 
        !           178:        status = os->get_default_pwd_status(os);
        !           179:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_DEFAULT_PWD_ENABLED,
        !           180:                                status ? "yes" : "no");
        !           181:        attr = generic_attr_bool_create(status,
        !           182:                                pen_type_create(PEN_PWG, PWG_HCD_DEFAULT_PWD_ENABLED));
        !           183:        msg->add_attribute(msg, attr);
        !           184: }
        !           185: 
        !           186: /**
        !           187:  * Add ForwardingEnabled attribute to send queue
        !           188:  */
        !           189: static void add_forwarding_enabled(imc_msg_t *msg)
        !           190: {
        !           191:        pa_tnc_attr_t *attr;
        !           192:        os_fwd_status_t fwd_status;
        !           193: 
        !           194:        fwd_status = os->get_fwd_status(os);
        !           195:        DBG2(DBG_IMC, "  %N: %N", pwg_attr_names, PWG_HCD_FORWARDING_ENABLED,
        !           196:                                os_fwd_status_names, fwd_status);
        !           197:        attr = ietf_attr_fwd_enabled_create(fwd_status,
        !           198:                                pen_type_create(PEN_PWG, PWG_HCD_FORWARDING_ENABLED));
        !           199:        msg->add_attribute(msg, attr);
        !           200: }
        !           201: 
        !           202: /**
        !           203:  * Add MachineTypeModel attribute to send queue
        !           204:  */
        !           205: static void add_machine_type_model(imc_msg_t *msg)
        !           206: {
        !           207:        pa_tnc_attr_t *attr;
        !           208:        char *string;
        !           209: 
        !           210:        string = lib->settings->get_str(lib->settings,
        !           211:                                "%s.plugins.imc-hcd.subtypes.system.machine_type_model",
        !           212:                                "", lib->ns);
        !           213:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_MACHINE_TYPE_MODEL,
        !           214:                                string);
        !           215:        attr = generic_attr_string_create(chunk_from_str(string),
        !           216:                                pen_type_create(PEN_PWG, PWG_HCD_MACHINE_TYPE_MODEL));
        !           217:        msg->add_attribute(msg, attr);
        !           218: }
        !           219: 
        !           220: /**
        !           221:  * Add PSTNFaxEnabled attribute to send queue
        !           222:  */
        !           223: static void add_pstn_fax_enabled(imc_msg_t *msg)
        !           224: {
        !           225:        pa_tnc_attr_t *attr;
        !           226:        bool status;
        !           227: 
        !           228:        status = lib->settings->get_bool(lib->settings,
        !           229:                                "%s.plugins.imc-hcd.subtypes.system.pstn_fax_enabled",
        !           230:                                FALSE, lib->ns);
        !           231:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_PSTN_FAX_ENABLED,
        !           232:                                status ? "yes" : "no");
        !           233:        attr = generic_attr_bool_create(status,
        !           234:                                pen_type_create(PEN_PWG, PWG_HCD_PSTN_FAX_ENABLED));
        !           235:        msg->add_attribute(msg, attr);
        !           236: }
        !           237: 
        !           238: /**
        !           239:  * Add TimeSource attribute to send queue
        !           240:  */
        !           241: static void add_time_source(imc_msg_t *msg)
        !           242: {
        !           243:        pa_tnc_attr_t *attr;
        !           244:        char *string;
        !           245: 
        !           246:        string = lib->settings->get_str(lib->settings,
        !           247:                                "%s.plugins.imc-hcd.subtypes.system.time_source",
        !           248:                                "", lib->ns);
        !           249:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_TIME_SOURCE,
        !           250:                                string);
        !           251:        attr = generic_attr_string_create(chunk_from_str(string),
        !           252:                                pen_type_create(PEN_PWG, PWG_HCD_TIME_SOURCE));
        !           253:        msg->add_attribute(msg, attr);
        !           254: }
        !           255: 
        !           256: /**
        !           257:  * Add UserApplicationEnabled attribute to send queue
        !           258:  */
        !           259: static void add_user_app_enabled(imc_msg_t *msg)
        !           260: {
        !           261:        pa_tnc_attr_t *attr;
        !           262:        bool status;
        !           263: 
        !           264:        status = lib->settings->get_bool(lib->settings,
        !           265:                                "%s.plugins.imc-hcd.subtypes.system.user_application_enabled",
        !           266:                                FALSE, lib->ns);
        !           267:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_USER_APP_ENABLED,
        !           268:                                status ? "yes" : "no");
        !           269:        attr = generic_attr_bool_create(status,
        !           270:                                pen_type_create(PEN_PWG, PWG_HCD_USER_APP_ENABLED));
        !           271:        msg->add_attribute(msg, attr);
        !           272: }
        !           273: 
        !           274: /**
        !           275:  * Add UserApplicationPersistenceEnabled attribute to send queue
        !           276:  */
        !           277: static void add_user_app_persist_enabled(imc_msg_t *msg)
        !           278: {
        !           279:        pa_tnc_attr_t *attr;
        !           280:        bool status;
        !           281: 
        !           282:        status = lib->settings->get_bool(lib->settings,
        !           283:                                "%s.plugins.imc-hcd.subtypes.system.user_application_persistence.enabled",
        !           284:                                FALSE, lib->ns);
        !           285:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_USER_APP_PERSIST_ENABLED,
        !           286:                                status ? "yes" : "no");
        !           287:        attr = generic_attr_bool_create(status,
        !           288:                                pen_type_create(PEN_PWG, PWG_HCD_USER_APP_PERSIST_ENABLED));
        !           289:        msg->add_attribute(msg, attr);
        !           290: }
        !           291: 
        !           292: /**
        !           293:  * Add VendorName attribute to send queue
        !           294:  */
        !           295: static void add_vendor_name(imc_msg_t *msg)
        !           296: {
        !           297:        pa_tnc_attr_t *attr;
        !           298:        char *string;
        !           299: 
        !           300:        string = lib->settings->get_str(lib->settings,
        !           301:                                "%s.plugins.imc-hcd.subtypes.system.vendor_name",
        !           302:                                "", lib->ns);
        !           303:        DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, PWG_HCD_VENDOR_NAME,
        !           304:                                string);
        !           305:        attr = generic_attr_string_create(chunk_from_str(string),
        !           306:                                pen_type_create(PEN_PWG, PWG_HCD_VENDOR_NAME));
        !           307:        msg->add_attribute(msg, attr);
        !           308: }
        !           309: 
        !           310: /**
        !           311:  * Add VendorSMICode attribute to send queue
        !           312:  */
        !           313: static void add_vendor_smi_code(imc_msg_t *msg)
        !           314: {
        !           315:        pa_tnc_attr_t *attr;
        !           316:        int smi_code;
        !           317: 
        !           318:        smi_code = lib->settings->get_int(lib->settings,
        !           319:                                "%s.plugins.imc-hcd.subtypes.system.vendor_smi_code",
        !           320:                                0, lib->ns);
        !           321:        DBG2(DBG_IMC, "  %N: 0x%06x (%d)", pwg_attr_names, PWG_HCD_VENDOR_SMI_CODE,
        !           322:                                smi_code, smi_code);
        !           323:        attr = pwg_attr_vendor_smi_code_create(smi_code);
        !           324:        msg->add_attribute(msg, attr);
        !           325: }
        !           326: 
        !           327: /**
        !           328:  * Add CertificationState attribute to send queue
        !           329:  */
        !           330: static void add_certification_state(imc_msg_t *msg)
        !           331: {
        !           332:        pa_tnc_attr_t *attr;
        !           333:        char *hex_string;
        !           334:        chunk_t blob;
        !           335: 
        !           336:        hex_string = lib->settings->get_str(lib->settings,
        !           337:                                        "%s.plugins.imc-hcd.subtypes.system.certification_state",
        !           338:                                        NULL, lib->ns);
        !           339:        if (hex_string)
        !           340:        {
        !           341:                blob = chunk_from_hex(chunk_from_str(hex_string), NULL);
        !           342: 
        !           343:                DBG2(DBG_IMC, "  %N: %B", pwg_attr_names, PWG_HCD_CERTIFICATION_STATE,
        !           344:                                        &blob);
        !           345:                attr = generic_attr_chunk_create(blob,
        !           346:                                        pen_type_create(PEN_PWG, PWG_HCD_CERTIFICATION_STATE));
        !           347:                msg->add_attribute(msg, attr);
        !           348:                chunk_free(&blob);
        !           349:        }
        !           350: }
        !           351: 
        !           352: /**
        !           353:  * Add CertificationState attribute to send queue
        !           354:  */
        !           355: static void add_configuration_state(imc_msg_t *msg)
        !           356: {
        !           357:        pa_tnc_attr_t *attr;
        !           358:        char *hex_string;
        !           359:        chunk_t blob;
        !           360: 
        !           361:        hex_string = lib->settings->get_str(lib->settings,
        !           362:                                        "%s.plugins.imc-hcd.subtypes.system.configuration_state",
        !           363:                                        NULL, lib->ns);
        !           364:        if (hex_string)
        !           365:        {
        !           366:                blob = chunk_from_hex(chunk_from_str(hex_string), NULL);
        !           367: 
        !           368:                DBG2(DBG_IMC, "  %N: %B", pwg_attr_names, PWG_HCD_CONFIGURATION_STATE,
        !           369:                                        &blob);
        !           370:                attr = generic_attr_chunk_create(blob,
        !           371:                                        pen_type_create(PEN_PWG, PWG_HCD_CONFIGURATION_STATE));
        !           372:                msg->add_attribute(msg, attr);
        !           373:                chunk_free(&blob);
        !           374:        }
        !           375: }
        !           376: 
        !           377: /**
        !           378:  * Add Correlated Attributes to send queue
        !           379:  */
        !           380: static void add_quadruple(imc_msg_t *msg, char *section, quadruple_t *quad)
        !           381: {
        !           382:        pa_tnc_attr_t *attr;
        !           383:        const size_t version_len = 16;
        !           384:        char version[version_len];
        !           385:        char hex_version_default[] = "00000000000000000000000000000000";
        !           386:        char *app, *name, *patches, *string_version, *hex_version;
        !           387:        size_t len;
        !           388:        chunk_t num_version;
        !           389:        enumerator_t *enumerator;
        !           390: 
        !           391:        enumerator = lib->settings->create_section_enumerator(lib->settings,
        !           392:                                        "%s.plugins.imc-hcd.subtypes.%s.%s",
        !           393:                                        lib->ns, section, quad->section);
        !           394:        while (enumerator->enumerate(enumerator, &app))
        !           395:        {
        !           396:                name = lib->settings->get_str(lib->settings,
        !           397:                                        "%s.plugins.imc-hcd.subtypes.%s.%s.%s.name",
        !           398:                                        "",     lib->ns, section, quad->section, app);
        !           399:                patches = lib->settings->get_str(lib->settings,
        !           400:                                        "%s.plugins.imc-hcd.subtypes.%s.%s.%s.patches",
        !           401:                                        "", lib->ns, section, quad->section, app);
        !           402:                string_version = lib->settings->get_str(lib->settings,
        !           403:                                        "%s.plugins.imc-hcd.subtypes.%s.%s.%s.string_version",
        !           404:                                        "",     lib->ns, section, quad->section, app);
        !           405:                hex_version = lib->settings->get_str(lib->settings,
        !           406:                                        "%s.plugins.imc-hcd.subtypes.%s.%s.%s.version",
        !           407:                                        hex_version_default, lib->ns, section, quad->section, app);
        !           408: 
        !           409:                /* convert hex string into binary chunk */
        !           410:                if (strlen(hex_version) > 2 * version_len)
        !           411:                {
        !           412:                        hex_version = hex_version_default;
        !           413:                }
        !           414:                num_version = chunk_from_hex(chunk_from_str(hex_version), version);
        !           415: 
        !           416:                DBG2(DBG_IMC, "--- %s ---", app);
        !           417: 
        !           418:                DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, quad->name_attr, name);
        !           419:                attr = generic_attr_string_create(chunk_from_str(name),
        !           420:                                                pen_type_create(PEN_PWG, quad->name_attr));
        !           421:                msg->add_attribute(msg, attr);
        !           422: 
        !           423:                /* remove any trailing LF from patches string for logging */
        !           424:                len = strlen(patches);
        !           425:                if (len && (patches[len - 1] == '\n'))
        !           426:                {
        !           427:                        len--;
        !           428:                }
        !           429:                DBG2(DBG_IMC, "  %N:%s%.*s", pwg_attr_names, quad->patches_attr,
        !           430:                                                len ? "\n" : " ", len, patches);
        !           431:                attr = generic_attr_string_create(chunk_from_str(patches),
        !           432:                                                pen_type_create(PEN_PWG, quad->patches_attr));
        !           433:                msg->add_attribute(msg, attr);
        !           434: 
        !           435:                DBG2(DBG_IMC, "  %N: %s", pwg_attr_names, quad->string_version_attr,
        !           436:                                                string_version);
        !           437:                attr = generic_attr_string_create(chunk_from_str(string_version),
        !           438:                                                pen_type_create(PEN_PWG, quad->string_version_attr));
        !           439:                msg->add_attribute(msg, attr);
        !           440: 
        !           441:                DBG2(DBG_IMC, "  %N: %#B", pwg_attr_names, quad->version_attr, &num_version);
        !           442:                attr = generic_attr_chunk_create(num_version,
        !           443:                                                pen_type_create(PEN_PWG, quad->version_attr));
        !           444:                msg->add_attribute(msg, attr);
        !           445:        }
        !           446:        enumerator->destroy(enumerator);
        !           447: }
        !           448: 
        !           449: /**
        !           450:  * see section 3.8.3 of TCG TNC IF-IMC Specification 1.3
        !           451:  */
        !           452: TNC_Result TNC_IMC_API TNC_IMC_BeginHandshake(TNC_IMCID imc_id,
        !           453:                                                                                          TNC_ConnectionID connection_id)
        !           454: {
        !           455:        imc_state_t *state;
        !           456:        imc_msg_t *out_msg;
        !           457:        TNC_Result result = TNC_RESULT_SUCCESS;
        !           458:        pa_subtype_pwg_t subtype;
        !           459:        pen_type_t msg_type;
        !           460:        enumerator_t *enumerator;
        !           461:        char *section;
        !           462:        int i;
        !           463: 
        !           464:        if (!imc_hcd)
        !           465:        {
        !           466:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           467:                return TNC_RESULT_NOT_INITIALIZED;
        !           468:        }
        !           469:        if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
        !           470:        {
        !           471:                return TNC_RESULT_FATAL;
        !           472:        }
        !           473: 
        !           474:        /* Enumerate over all HCD subtype sections */
        !           475:        enumerator = lib->settings->create_section_enumerator(lib->settings,
        !           476:                                                "%s.plugins.imc-hcd.subtypes", lib->ns);
        !           477:        while (enumerator->enumerate(enumerator, &section) &&
        !           478:                   result == TNC_RESULT_SUCCESS)
        !           479:        {
        !           480:                subtype = PA_SUBTYPE_PWG_HCD_UNKNOWN;
        !           481: 
        !           482:                for (i = 0; i < countof(section_subtypes); i++)
        !           483:                {
        !           484:                        if (streq(section, section_subtypes[i].section))
        !           485:                        {
        !           486:                                subtype = section_subtypes[i].subtype;
        !           487:                                break;
        !           488:                        }
        !           489:                }
        !           490:                if (subtype == PA_SUBTYPE_PWG_HCD_UNKNOWN)
        !           491:                {
        !           492:                        DBG1(DBG_IMC, "HCD subtype '%s' not supported", section);
        !           493:                        continue;
        !           494:                }
        !           495:                DBG2(DBG_IMC, "retrieving attributes for PA subtype %N/%N",
        !           496:                         pen_names, PEN_PWG, pa_subtype_pwg_names, subtype);
        !           497: 
        !           498:                msg_type = pen_type_create(PEN_PWG, subtype);
        !           499:                out_msg = imc_msg_create(imc_hcd, state, connection_id, imc_id,
        !           500:                                                                 TNC_IMVID_ANY, msg_type);
        !           501: 
        !           502:                /* mandatory attributes that are always sent without request */
        !           503:                add_attrs_natural_lang(out_msg, section);
        !           504:                if (subtype == PA_SUBTYPE_PWG_HCD_SYSTEM)
        !           505:                {
        !           506:                        add_default_pwd_enabled(out_msg);
        !           507:                        add_forwarding_enabled(out_msg);
        !           508:                        add_machine_type_model(out_msg);
        !           509:                        add_pstn_fax_enabled(out_msg);
        !           510:                        add_time_source(out_msg);
        !           511:                        add_vendor_name(out_msg);
        !           512:                        add_vendor_smi_code(out_msg);
        !           513:                        add_user_app_enabled(out_msg);
        !           514:                        add_user_app_persist_enabled(out_msg);
        !           515:                }
        !           516:                if (lib->settings->get_bool(lib->settings,
        !           517:                                                                "%s.plugins.imc-hcd.push_info", FALSE, lib->ns))
        !           518:                {
        !           519:                        /* correlated attributes */
        !           520:                        for (i = 0; i < countof(quadruples); i++)
        !           521:                        {
        !           522:                                add_quadruple(out_msg, section, &quadruples[i]);
        !           523:                        }
        !           524:                }
        !           525: 
        !           526:                /* send PA-TNC message with the excl flag not set */
        !           527:                result = out_msg->send(out_msg, FALSE);
        !           528:                out_msg->destroy(out_msg);
        !           529:        }
        !           530:        enumerator->destroy(enumerator);
        !           531: 
        !           532:        return result;
        !           533: }
        !           534: 
        !           535: static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
        !           536: {
        !           537:        imc_msg_t *out_msg;
        !           538:        enumerator_t *enumerator;
        !           539:        pa_tnc_attr_t *attr;
        !           540:        pen_type_t type, msg_type;
        !           541:        TNC_Result result;
        !           542:        char *section = NULL;
        !           543:        int i;
        !           544:        bool fatal_error = FALSE, pushed_info;
        !           545: 
        !           546:        /* generate an outgoing PA-TNC message - we might need it */
        !           547:        out_msg = imc_msg_create_as_reply(in_msg);
        !           548: 
        !           549:        /* parse received PA-TNC message and handle local and remote errors */
        !           550:        result = in_msg->receive(in_msg, out_msg, &fatal_error);
        !           551:        if (result != TNC_RESULT_SUCCESS)
        !           552:        {
        !           553:                out_msg->destroy(out_msg);
        !           554:                return result;
        !           555:        }
        !           556:        msg_type = in_msg->get_msg_type(in_msg);
        !           557: 
        !           558:        for (i = 0; i < countof(section_subtypes); i++)
        !           559:        {
        !           560:                if (msg_type.type == section_subtypes[i].subtype)
        !           561:                {
        !           562:                        section = section_subtypes[i].section;
        !           563:                        break;
        !           564:                }
        !           565:        }
        !           566:        pushed_info = lib->settings->get_bool(lib->settings,
        !           567:                                                "%s.plugins.imc-hcd.push_info", FALSE, lib->ns);
        !           568: 
        !           569:        /* analyze PA-TNC attributes */
        !           570:        enumerator = in_msg->create_attribute_enumerator(in_msg);
        !           571:        while (enumerator->enumerate(enumerator, &attr))
        !           572:        {
        !           573:                type = attr->get_type(attr);
        !           574: 
        !           575:                if (type.vendor_id == PEN_IETF)
        !           576:                {
        !           577:                        if (type.type == IETF_ATTR_ATTRIBUTE_REQUEST)
        !           578:                        {
        !           579:                                ietf_attr_attr_request_t *attr_cast;
        !           580:                                pen_type_t *entry;
        !           581:                                enumerator_t *e;
        !           582: 
        !           583:                                attr_cast = (ietf_attr_attr_request_t*)attr;
        !           584: 
        !           585:                                e = attr_cast->create_enumerator(attr_cast);
        !           586:                                while (e->enumerate(e, &entry))
        !           587:                                {
        !           588:                                        if (entry->vendor_id == PEN_PWG)
        !           589:                                        {
        !           590:                                                switch (entry->type)
        !           591:                                                {
        !           592:                                                        case PWG_HCD_ATTRS_NATURAL_LANG:
        !           593:                                                                add_attrs_natural_lang(out_msg, section);
        !           594:                                                                break;
        !           595:                                                        case PWG_HCD_DEFAULT_PWD_ENABLED:
        !           596:                                                                add_default_pwd_enabled(out_msg);
        !           597:                                                                break;
        !           598:                                                        case PWG_HCD_FORWARDING_ENABLED:
        !           599:                                                                add_forwarding_enabled(out_msg);
        !           600:                                                                break;
        !           601:                                                        case PWG_HCD_MACHINE_TYPE_MODEL:
        !           602:                                                                add_machine_type_model(out_msg);
        !           603:                                                                break;
        !           604:                                                        case PWG_HCD_PSTN_FAX_ENABLED:
        !           605:                                                                add_pstn_fax_enabled(out_msg);
        !           606:                                                                break;
        !           607:                                                        case PWG_HCD_TIME_SOURCE:
        !           608:                                                                add_time_source(out_msg);
        !           609:                                                                break;
        !           610:                                                        case PWG_HCD_USER_APP_ENABLED:
        !           611:                                                                add_user_app_enabled(out_msg);
        !           612:                                                                break;
        !           613:                                                        case PWG_HCD_USER_APP_PERSIST_ENABLED:
        !           614:                                                                add_user_app_persist_enabled(out_msg);
        !           615:                                                                break;
        !           616:                                                        case PWG_HCD_VENDOR_NAME:
        !           617:                                                                add_vendor_name(out_msg);
        !           618:                                                                break;
        !           619:                                                        case PWG_HCD_VENDOR_SMI_CODE:
        !           620:                                                                add_vendor_smi_code(out_msg);
        !           621:                                                                break;
        !           622:                                                        case PWG_HCD_CERTIFICATION_STATE:
        !           623:                                                                add_certification_state(out_msg);
        !           624:                                                                break;
        !           625:                                                        case PWG_HCD_CONFIGURATION_STATE:
        !           626:                                                                add_configuration_state(out_msg);
        !           627:                                                                break;
        !           628:                                                        default:
        !           629:                                                                if (pushed_info)
        !           630:                                                                {
        !           631:                                                                        continue;
        !           632:                                                                }
        !           633:                                                }
        !           634: 
        !           635:                                                /* if not pushed, deliver on request */
        !           636:                                                switch (entry->type)
        !           637:                                                {
        !           638:                                                        case PWG_HCD_FIRMWARE_NAME:
        !           639:                                                                add_quadruple(out_msg, section, &quadruples[0]);
        !           640:                                                                break;
        !           641:                                                        case PWG_HCD_RESIDENT_APP_NAME:
        !           642:                                                                add_quadruple(out_msg, section, &quadruples[1]);
        !           643:                                                                break;
        !           644:                                                        case PWG_HCD_USER_APP_NAME:
        !           645:                                                                add_quadruple(out_msg, section, &quadruples[2]);
        !           646:                                                                break;
        !           647:                                                        default:
        !           648:                                                                break;
        !           649:                                                }
        !           650:                                        }
        !           651:                                }
        !           652:                                e->destroy(e);
        !           653:                        }
        !           654:                }
        !           655:        }
        !           656:        enumerator->destroy(enumerator);
        !           657: 
        !           658:        if (fatal_error)
        !           659:        {
        !           660:                result = TNC_RESULT_FATAL;
        !           661:        }
        !           662:        else
        !           663:        {
        !           664:                /* send PA-TNC message with the EXCL flag set */
        !           665:                result = out_msg->send(out_msg, TRUE);
        !           666:        }
        !           667:        out_msg->destroy(out_msg);
        !           668: 
        !           669:        return result;
        !           670: }
        !           671: 
        !           672: /**
        !           673:  * see section 3.8.4 of TCG TNC IF-IMC Specification 1.3
        !           674:  */
        !           675: TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
        !           676:                                                                                          TNC_ConnectionID connection_id,
        !           677:                                                                                          TNC_BufferReference msg,
        !           678:                                                                                          TNC_UInt32 msg_len,
        !           679:                                                                                          TNC_MessageType msg_type)
        !           680: {
        !           681:        imc_state_t *state;
        !           682:        imc_msg_t *in_msg;
        !           683:        TNC_Result result;
        !           684: 
        !           685:        if (!imc_hcd)
        !           686:        {
        !           687:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           688:                return TNC_RESULT_NOT_INITIALIZED;
        !           689:        }
        !           690:        if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
        !           691:        {
        !           692:                return TNC_RESULT_FATAL;
        !           693:        }
        !           694:        in_msg = imc_msg_create_from_data(imc_hcd, state, connection_id, msg_type,
        !           695:                                                                          chunk_create(msg, msg_len));
        !           696:        result = receive_message(state, in_msg);
        !           697:        in_msg->destroy(in_msg);
        !           698: 
        !           699:        return result;
        !           700: }
        !           701: 
        !           702: /**
        !           703:  * see section 3.8.6 of TCG TNC IF-IMV Specification 1.3
        !           704:  */
        !           705: TNC_Result TNC_IMC_API TNC_IMC_ReceiveMessageLong(TNC_IMCID imc_id,
        !           706:                                                                                                  TNC_ConnectionID connection_id,
        !           707:                                                                                                  TNC_UInt32 msg_flags,
        !           708:                                                                                                  TNC_BufferReference msg,
        !           709:                                                                                                  TNC_UInt32 msg_len,
        !           710:                                                                                                  TNC_VendorID msg_vid,
        !           711:                                                                                                  TNC_MessageSubtype msg_subtype,
        !           712:                                                                                                  TNC_UInt32 src_imv_id,
        !           713:                                                                                                  TNC_UInt32 dst_imc_id)
        !           714: {
        !           715:        imc_state_t *state;
        !           716:        imc_msg_t *in_msg;
        !           717:        TNC_Result result;
        !           718: 
        !           719:        if (!imc_hcd)
        !           720:        {
        !           721:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           722:                return TNC_RESULT_NOT_INITIALIZED;
        !           723:        }
        !           724:        if (!imc_hcd->get_state(imc_hcd, connection_id, &state))
        !           725:        {
        !           726:                return TNC_RESULT_FATAL;
        !           727:        }
        !           728:        in_msg = imc_msg_create_from_long_data(imc_hcd, state, connection_id,
        !           729:                                                                src_imv_id, dst_imc_id,msg_vid, msg_subtype,
        !           730:                                                                chunk_create(msg, msg_len));
        !           731:        result =receive_message(state, in_msg);
        !           732:        in_msg->destroy(in_msg);
        !           733: 
        !           734:        return result;
        !           735: }
        !           736: 
        !           737: /**
        !           738:  * see section 3.8.7 of TCG TNC IF-IMC Specification 1.3
        !           739:  */
        !           740: TNC_Result TNC_IMC_API TNC_IMC_BatchEnding(TNC_IMCID imc_id,
        !           741:                                                                                   TNC_ConnectionID connection_id)
        !           742: {
        !           743:        if (!imc_hcd)
        !           744:        {
        !           745:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           746:                return TNC_RESULT_NOT_INITIALIZED;
        !           747:        }
        !           748:        return TNC_RESULT_SUCCESS;
        !           749: }
        !           750: 
        !           751: /**
        !           752:  * see section 3.8.8 of TCG TNC IF-IMC Specification 1.3
        !           753:  */
        !           754: TNC_Result TNC_IMC_API TNC_IMC_Terminate(TNC_IMCID imc_id)
        !           755: {
        !           756:        if (!imc_hcd)
        !           757:        {
        !           758:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           759:                return TNC_RESULT_NOT_INITIALIZED;
        !           760:        }
        !           761:        imc_hcd->destroy(imc_hcd);
        !           762:        imc_hcd = NULL;
        !           763: 
        !           764:        os->destroy(os);
        !           765:        os = NULL;
        !           766: 
        !           767:        return TNC_RESULT_SUCCESS;
        !           768: }
        !           769: 
        !           770: /**
        !           771:  * see section 4.2.8.1 of TCG TNC IF-IMC Specification 1.3
        !           772:  */
        !           773: TNC_Result TNC_IMC_API TNC_IMC_ProvideBindFunction(TNC_IMCID imc_id,
        !           774:                                                                        TNC_TNCC_BindFunctionPointer bind_function)
        !           775: {
        !           776:        if (!imc_hcd)
        !           777:        {
        !           778:                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
        !           779:                return TNC_RESULT_NOT_INITIALIZED;
        !           780:        }
        !           781:        return imc_hcd->bind_functions(imc_hcd, bind_function);
        !           782: }

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