1 /* alert.h -- DTLS alert protocol
2 *
3 * Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org>
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 /**
27 * @file alert.h
28 * @brief DTLS alert protocol
29 */
30
31 #ifndef _DTLS_ALERT_H_
32 #define _DTLS_ALERT_H_
33
34 typedef enum {
35 DTLS_ALERT_LEVEL_WARNING=1,
36 DTLS_ALERT_LEVEL_FATAL=2
37 } dtls_alert_level_t;
38
39 typedef enum {
40 DTLS_ALERT_CLOSE_NOTIFY = 0, /* close_notify */
41 DTLS_ALERT_UNEXPECTED_MESSAGE = 10, /* unexpected_message */
42 DTLS_ALERT_BAD_RECORD_MAC = 20, /* bad_record_mac */
43 DTLS_ALERT_RECORD_OVERFLOW = 22, /* record_overflow */
44 DTLS_ALERT_DECOMPRESSION_FAILURE = 30, /* decompression_failure */
45 DTLS_ALERT_HANDSHAKE_FAILURE = 40, /* handshake_failure */
46 DTLS_ALERT_BAD_CERTIFICATE = 42, /* bad_certificate */
47 DTLS_ALERT_UNSUPPORTED_CERTIFICATE = 43, /* unsupported_certificate */
48 DTLS_ALERT_CERTIFICATE_REVOKED = 44, /* certificate_revoked */
49 DTLS_ALERT_CERTIFICATE_EXPIRED = 45, /* certificate_expired */
50 DTLS_ALERT_CERTIFICATE_UNKNOWN = 46, /* certificate_unknown */
51 DTLS_ALERT_ILLEGAL_PARAMETER = 47, /* illegal_parameter */
52 DTLS_ALERT_UNKNOWN_CA = 48, /* unknown_ca */
53 DTLS_ALERT_ACCESS_DENIED = 49, /* access_denied */
54 DTLS_ALERT_DECODE_ERROR = 50, /* decode_error */
55 DTLS_ALERT_DECRYPT_ERROR = 51, /* decrypt_error */
56 DTLS_ALERT_PROTOCOL_VERSION = 70, /* protocol_version */
57 DTLS_ALERT_INSUFFICIENT_SECURITY = 71, /* insufficient_security */
58 DTLS_ALERT_INTERNAL_ERROR = 80, /* internal_error */
59 DTLS_ALERT_USER_CANCELED = 90, /* user_canceled */
60 DTLS_ALERT_NO_RENEGOTIATION = 100, /* no_renegotiation */
61 DTLS_ALERT_UNSUPPORTED_EXTENSION = 110 /* unsupported_extension */
62 } dtls_alert_t;
63
64 #define DTLS_EVENT_CONNECT 0x01DC /**< initiated handshake */
65 #define DTLS_EVENT_CONNECTED 0x01DE /**< handshake or re-negotiation
66 * has finished */
67 #define DTLS_EVENT_RENEGOTIATE 0x01DF /**< re-negotiation has started */
68
69 static inline int
dtls_alert_create(dtls_alert_level_t level,dtls_alert_t desc)70 dtls_alert_create(dtls_alert_level_t level, dtls_alert_t desc)
71 {
72 return -((level << 8) | desc);
73 }
74
75 static inline int
dtls_alert_fatal_create(dtls_alert_t desc)76 dtls_alert_fatal_create(dtls_alert_t desc)
77 {
78 return dtls_alert_create(DTLS_ALERT_LEVEL_FATAL, desc);
79 }
80
81 #endif /* _DTLS_ALERT_H_ */
82