]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libimcv/swima/swima_error.c
Some whitespace fixes
[thirdparty/strongswan.git] / src / libimcv / swima / swima_error.c
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 "swima_error.h"
17
18 #include <bio/bio_writer.h>
19 #include <ietf/ietf_attr_pa_tnc_error.h>
20
21 /**
22 * SW_ERROR, SW_SUBSCRIPTION_DENIED_ERROR and SW_SUBSCRIPTION_ID_REUSE_ERROR
23 *
24 * 1 2 3
25 * 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
26 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 * | Copy of Request ID / Subscription ID |
28 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 * | Description (variable length) |
30 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 */
32
33 /**
34 * SW_RESPONSE_TOO_LARGE_ERROR
35 *
36 * 1 2 3
37 * 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
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Copy of Request ID / Subscription ID |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Maximum Allowed Size |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Description (variable length) |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 */
46
47 /**
48 * Described in header.
49 */
50 pa_tnc_attr_t* swima_error_create(pa_tnc_error_code_t code, uint32_t request_id,
51 uint32_t max_attr_size, char *description)
52 {
53 bio_writer_t *writer;
54 chunk_t msg_info;
55 pa_tnc_attr_t *attr;
56 pen_type_t error_code;
57
58 error_code = pen_type_create( PEN_IETF, code);
59 writer = bio_writer_create(4);
60 writer->write_uint32(writer, request_id);
61
62 if (code == PA_ERROR_SWIMA_RESPONSE_TOO_LARGE)
63 {
64 writer->write_uint32(writer, max_attr_size);
65 }
66
67 if (description)
68 {
69 writer->write_data(writer, chunk_from_str(description));
70 }
71 msg_info = writer->get_buf(writer);
72 attr = ietf_attr_pa_tnc_error_create(error_code, msg_info);
73 writer->destroy(writer);
74
75 return attr;
76 }
77