-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.c
64 lines (62 loc) · 1.74 KB
/
handlers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <coap2/coap.h>
#include <stdio.h>
int event_handler(coap_context_t *ctx, coap_event_t event,
coap_session_t *session) {
switch (event) {
case COAP_EVENT_DTLS_CLOSED:
printf("Event: DTLS closed\n");
break;
case COAP_EVENT_DTLS_CONNECTED:
printf("Event: DTLS connected\n");
break;
case COAP_EVENT_DTLS_RENEGOTIATE:
printf("Event: DTLS renegotiate\n");
break;
case COAP_EVENT_DTLS_ERROR:
printf("Event: DTLS error\n");
break;
case COAP_EVENT_TCP_CONNECTED:
printf("Event: TCP connected\n");
break;
case COAP_EVENT_TCP_CLOSED:
printf("Event: TCP closed\n");
break;
case COAP_EVENT_TCP_FAILED:
printf("Event: TCP failed\n");
break;
case COAP_EVENT_SESSION_CONNECTED:
printf("Event: Session connected\n");
break;
case COAP_EVENT_SESSION_CLOSED:
printf("Event: Session closed\n");
break;
case COAP_EVENT_SESSION_FAILED:
printf("Event: Session failed\n");
break;
default:
printf("Uknown CoAP event: %04x\n", event);
break;
}
return 0;
}
void nack_handler(coap_context_t *context, coap_session_t *session,
coap_pdu_t *sent, coap_nack_reason_t reason,
const coap_tid_t id) {
switch (reason) {
case COAP_NACK_TOO_MANY_RETRIES:
printf("CoAP NACK handler: reason: too many retries id=%d\n", id);
break;
case COAP_NACK_NOT_DELIVERABLE:
printf("CoAP NACK handler: reason: not deliverable id=%d\n", id);
break;
case COAP_NACK_RST:
printf("CoAP NACK handler: reason: RST id=%d\n", id);
break;
case COAP_NACK_TLS_FAILED:
printf("CoAP NACK handler: reason: TLS failed id=%d\n", id);
break;
default:
printf("CoAP NACK handler: reason=%d id=%d\n", reason, id);
break;
}
}