1 /*******************************************************************************
2  *
3  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  *
8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9  * and the Eclipse Distribution License is available at
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  *
12  * Contributors:
13  *    Olaf Bergmann  - initial API and implementation
14  *    Hauke Mehrtens - memory optimization, ECC integration
15  *
16  *******************************************************************************/
17 
18 /**
19  * @file alert.h
20  * @brief DTLS alert protocol
21  */
22 
23 #ifndef _DTLS_ALERT_H_
24 #define _DTLS_ALERT_H_
25 
26 typedef enum {
27   DTLS_ALERT_LEVEL_WARNING=1,
28   DTLS_ALERT_LEVEL_FATAL=2
29 } dtls_alert_level_t;
30 
31 typedef enum {
32   DTLS_ALERT_CLOSE_NOTIFY = 0,			/* close_notify */
33   DTLS_ALERT_UNEXPECTED_MESSAGE = 10,		/* unexpected_message */
34   DTLS_ALERT_BAD_RECORD_MAC = 20,		/* bad_record_mac */
35   DTLS_ALERT_RECORD_OVERFLOW = 22,		/* record_overflow */
36   DTLS_ALERT_DECOMPRESSION_FAILURE = 30,	/* decompression_failure */
37   DTLS_ALERT_HANDSHAKE_FAILURE = 40,		/* handshake_failure */
38   DTLS_ALERT_BAD_CERTIFICATE = 42,		/* bad_certificate */
39   DTLS_ALERT_UNSUPPORTED_CERTIFICATE = 43,	/* unsupported_certificate */
40   DTLS_ALERT_CERTIFICATE_REVOKED = 44,		/* certificate_revoked */
41   DTLS_ALERT_CERTIFICATE_EXPIRED = 45,		/* certificate_expired */
42   DTLS_ALERT_CERTIFICATE_UNKNOWN = 46,		/* certificate_unknown */
43   DTLS_ALERT_ILLEGAL_PARAMETER = 47,		/* illegal_parameter */
44   DTLS_ALERT_UNKNOWN_CA = 48,			/* unknown_ca */
45   DTLS_ALERT_ACCESS_DENIED = 49,		/* access_denied */
46   DTLS_ALERT_DECODE_ERROR = 50,			/* decode_error */
47   DTLS_ALERT_DECRYPT_ERROR = 51,		/* decrypt_error */
48   DTLS_ALERT_PROTOCOL_VERSION = 70,		/* protocol_version */
49   DTLS_ALERT_INSUFFICIENT_SECURITY = 71,	/* insufficient_security */
50   DTLS_ALERT_INTERNAL_ERROR = 80,		/* internal_error */
51   DTLS_ALERT_USER_CANCELED = 90,		/* user_canceled */
52   DTLS_ALERT_NO_RENEGOTIATION = 100,		/* no_renegotiation */
53   DTLS_ALERT_UNSUPPORTED_EXTENSION = 110	/* unsupported_extension */
54 } dtls_alert_t;
55 
56 #define DTLS_EVENT_CONNECT        0x01DC /**< initiated handshake */
57 #define DTLS_EVENT_CONNECTED      0x01DE /**< handshake or re-negotiation
58 					  * has finished */
59 #define DTLS_EVENT_RENEGOTIATE    0x01DF /**< re-negotiation has started */
60 
61 static inline int
dtls_alert_create(dtls_alert_level_t level,dtls_alert_t desc)62 dtls_alert_create(dtls_alert_level_t level, dtls_alert_t desc)
63 {
64   return -((level << 8) | desc);
65 }
66 
67 static inline int
dtls_alert_fatal_create(dtls_alert_t desc)68 dtls_alert_fatal_create(dtls_alert_t desc)
69 {
70   return dtls_alert_create(DTLS_ALERT_LEVEL_FATAL, desc);
71 }
72 
73 #endif /* _DTLS_ALERT_H_ */
74