Return to tcg_pts_attr_proto_caps.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libimcv / tcg / pts |
1.1 misho 1: /* 2: * Copyright (C) 2011-2012 Sansar Choinyambuu 3: * Copyright (C) 2011-2014 Andreas Steffen 4: * HSR Hochschule fuer Technik Rapperswil 5: * 6: * This program is free software; you can redistribute it and/or modify it 7: * under the terms of the GNU General Public License as published by the 8: * Free Software Foundation; either version 2 of the License, or (at your 9: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 10: * 11: * This program is distributed in the hope that it will be useful, but 12: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14: * for more details. 15: */ 16: 17: #include "tcg_pts_attr_proto_caps.h" 18: 19: #include <pa_tnc/pa_tnc_msg.h> 20: #include <bio/bio_writer.h> 21: #include <bio/bio_reader.h> 22: #include <utils/debug.h> 23: 24: typedef struct private_tcg_pts_attr_proto_caps_t private_tcg_pts_attr_proto_caps_t; 25: 26: /** 27: * PTS Protocol Capabilities 28: * see section 3.7 of PTS Protocol: Binding to TNC IF-M Specification 29: * 30: * 1 2 3 31: * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 32: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33: * | Reserved |C|V|D|T|X| 34: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35: * 36: */ 37: 38: #define PTS_PROTO_CAPS_SIZE 4 39: #define PTS_PROTO_CAPS_RESERVED 0x0000 40: 41: /** 42: * Private data of an tcg_pts_attr_proto_caps_t object. 43: */ 44: struct private_tcg_pts_attr_proto_caps_t { 45: 46: /** 47: * Public members of tcg_pts_attr_proto_caps_t 48: */ 49: tcg_pts_attr_proto_caps_t public; 50: 51: /** 52: * Vendor-specific attribute type 53: */ 54: pen_type_t type; 55: 56: 57: /** 58: * Length of attribute value 59: */ 60: size_t length; 61: 62: /** 63: * Attribute value or segment 64: */ 65: chunk_t value; 66: 67: /** 68: * Noskip flag 69: */ 70: bool noskip_flag; 71: 72: /** 73: * Set of flags 74: */ 75: pts_proto_caps_flag_t flags; 76: 77: /** 78: * Reference count 79: */ 80: refcount_t ref; 81: }; 82: 83: METHOD(pa_tnc_attr_t, get_type, pen_type_t, 84: private_tcg_pts_attr_proto_caps_t *this) 85: { 86: return this->type; 87: } 88: 89: METHOD(pa_tnc_attr_t, get_value, chunk_t, 90: private_tcg_pts_attr_proto_caps_t *this) 91: { 92: return this->value; 93: } 94: 95: METHOD(pa_tnc_attr_t, get_noskip_flag, bool, 96: private_tcg_pts_attr_proto_caps_t *this) 97: { 98: return this->noskip_flag; 99: } 100: 101: METHOD(pa_tnc_attr_t, set_noskip_flag,void, 102: private_tcg_pts_attr_proto_caps_t *this, bool noskip) 103: { 104: this->noskip_flag = noskip; 105: } 106: 107: METHOD(pa_tnc_attr_t, build, void, 108: private_tcg_pts_attr_proto_caps_t *this) 109: { 110: bio_writer_t *writer; 111: 112: if (this->value.ptr) 113: { 114: return; 115: } 116: writer = bio_writer_create(PTS_PROTO_CAPS_SIZE); 117: writer->write_uint16(writer, PTS_PROTO_CAPS_RESERVED); 118: writer->write_uint16(writer, this->flags); 119: 120: this->value = writer->extract_buf(writer); 121: this->length = this->value.len; 122: writer->destroy(writer); 123: } 124: 125: METHOD(pa_tnc_attr_t, process, status_t, 126: private_tcg_pts_attr_proto_caps_t *this, uint32_t *offset) 127: { 128: bio_reader_t *reader; 129: uint16_t reserved, flags; 130: 131: *offset = 0; 132: 133: if (this->value.len < this->length) 134: { 135: return NEED_MORE; 136: } 137: if (this->value.len < PTS_PROTO_CAPS_SIZE) 138: { 139: DBG1(DBG_TNC, "insufficient data for PTS Protocol Capabilities"); 140: return FAILED; 141: } 142: reader = bio_reader_create(this->value); 143: reader->read_uint16(reader, &reserved); 144: reader->read_uint16(reader, &flags); 145: this->flags = flags; 146: reader->destroy(reader); 147: 148: return SUCCESS; 149: } 150: 151: METHOD(pa_tnc_attr_t, add_segment, void, 152: private_tcg_pts_attr_proto_caps_t *this, chunk_t segment) 153: { 154: this->value = chunk_cat("mc", this->value, segment); 155: } 156: 157: METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, 158: private_tcg_pts_attr_proto_caps_t *this) 159: { 160: ref_get(&this->ref); 161: return &this->public.pa_tnc_attribute; 162: } 163: 164: METHOD(pa_tnc_attr_t, destroy, void, 165: private_tcg_pts_attr_proto_caps_t *this) 166: { 167: if (ref_put(&this->ref)) 168: { 169: free(this->value.ptr); 170: free(this); 171: } 172: } 173: 174: METHOD(tcg_pts_attr_proto_caps_t, get_flags, pts_proto_caps_flag_t, 175: private_tcg_pts_attr_proto_caps_t *this) 176: { 177: return this->flags; 178: } 179: 180: /** 181: * Described in header. 182: */ 183: pa_tnc_attr_t *tcg_pts_attr_proto_caps_create(pts_proto_caps_flag_t flags, 184: bool request) 185: { 186: private_tcg_pts_attr_proto_caps_t *this; 187: 188: INIT(this, 189: .public = { 190: .pa_tnc_attribute = { 191: .get_type = _get_type, 192: .get_value = _get_value, 193: .get_noskip_flag = _get_noskip_flag, 194: .set_noskip_flag = _set_noskip_flag, 195: .build = _build, 196: .process = _process, 197: .add_segment = _add_segment, 198: .get_ref = _get_ref, 199: .destroy = _destroy, 200: }, 201: .get_flags = _get_flags, 202: }, 203: .type = { PEN_TCG, 204: request ? TCG_PTS_REQ_PROTO_CAPS : TCG_PTS_PROTO_CAPS }, 205: .flags = flags, 206: .ref = 1, 207: ); 208: 209: return &this->public.pa_tnc_attribute; 210: } 211: 212: /** 213: * Described in header. 214: */ 215: pa_tnc_attr_t *tcg_pts_attr_proto_caps_create_from_data(size_t length, 216: chunk_t data, 217: bool request) 218: { 219: private_tcg_pts_attr_proto_caps_t *this; 220: 221: INIT(this, 222: .public = { 223: .pa_tnc_attribute = { 224: .get_type = _get_type, 225: .get_value = _get_value, 226: .get_noskip_flag = _get_noskip_flag, 227: .set_noskip_flag = _set_noskip_flag, 228: .build = _build, 229: .process = _process, 230: .add_segment = _add_segment, 231: .get_ref = _get_ref, 232: .destroy = _destroy, 233: }, 234: .get_flags = _get_flags, 235: }, 236: .type = { PEN_TCG, 237: request ? TCG_PTS_REQ_PROTO_CAPS : TCG_PTS_PROTO_CAPS }, 238: .length = length, 239: .value = chunk_clone(data), 240: .ref = 1, 241: ); 242: 243: return &this->public.pa_tnc_attribute; 244: }