libcoap
4.1.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Groups
Pages
net.h
Go to the documentation of this file.
1
/* net.h -- CoAP network interface
2
*
3
* Copyright (C) 2010--2013 Olaf Bergmann <bergmann@tzi.org>
4
*
5
* This file is part of the CoAP library libcoap. Please see
6
* README for terms of use.
7
*/
8
9
#ifndef _COAP_NET_H_
10
#define _COAP_NET_H_
11
12
#ifdef __cplusplus
13
extern
"C"
{
14
#endif
15
16
#include "
config.h
"
17
18
#ifdef HAVE_ASSERT_H
19
#include <assert.h>
20
#else
21
#ifndef assert
22
#warning "assertions are disabled"
23
# define assert(x)
24
#endif
25
#endif
26
27
#include <stdlib.h>
28
#include <string.h>
29
#ifdef HAVE_NETINET_IN_H
30
#include <netinet/in.h>
31
#endif
32
#ifdef HAVE_TIME_H
33
#include <time.h>
34
#endif
35
#ifdef HAVE_SYS_TIME_H
36
#include <sys/time.h>
37
#endif
38
39
#ifdef WITH_LWIP
40
#include <lwip/ip_addr.h>
41
#endif
42
43
#include "
option.h
"
44
#include "
address.h
"
45
#include "
prng.h
"
46
#include "
pdu.h
"
47
#include "
coap_time.h
"
48
49
struct
coap_queue_t
;
50
51
typedef
struct
coap_queue_t
{
52
struct
coap_queue_t
*
next
;
53
54
coap_tick_t
t
;
55
unsigned
char
retransmit_cnt
;
56
unsigned
int
timeout
;
58
coap_address_t
local
;
59
coap_address_t
remote
;
60
coap_tid_t
id
;
62
coap_pdu_t
*
pdu
;
63
}
coap_queue_t
;
64
66
int
coap_insert_node
(
coap_queue_t
**queue,
coap_queue_t
*node);
67
69
int
coap_delete_node
(
coap_queue_t
*node);
70
72
void
coap_delete_all
(
coap_queue_t
*queue);
73
75
coap_queue_t
*
coap_new_node
();
76
77
struct
coap_resource_t
;
78
struct
coap_context_t
;
79
#ifndef WITHOUT_ASYNC
80
struct
coap_async_state_t
;
81
#endif
82
84
typedef
void (*
coap_response_handler_t
)(
struct
coap_context_t
*,
85
const
coap_address_t *remote,
86
coap_pdu_t
*sent,
87
coap_pdu_t
*received,
88
const
coap_tid_t
id
);
89
90
#define COAP_MID_CACHE_SIZE 3
91
typedef
struct
{
92
unsigned
char
flags
[
COAP_MID_CACHE_SIZE
];
93
coap_key_t
item[
COAP_MID_CACHE_SIZE
];
94
}
coap_mid_cache_t
;
95
97
typedef
struct
coap_context_t
{
98
coap_opt_filter_t
known_options
;
99
#ifndef WITH_CONTIKI
100
struct
coap_resource_t
*
resources
;
101
#endif
/* WITH_CONTIKI */
102
#ifndef WITHOUT_ASYNC
103
104
struct
coap_async_state_t
*
async_state
;
105
#endif
/* WITHOUT_ASYNC */
106
109
coap_tick_t
sendqueue_basetime
;
110
coap_queue_t
*
sendqueue
, *
recvqueue
;
111
#if WITH_POSIX
112
int
sockfd;
113
#endif
/* WITH_POSIX */
114
#ifdef WITH_CONTIKI
115
struct
uip_udp_conn *conn;
117
struct
etimer retransmit_timer;
118
struct
etimer notify_timer;
119
#endif
/* WITH_CONTIKI */
120
#ifdef WITH_LWIP
121
struct
udp_pcb *pcb;
122
struct
pbuf *pending_package;
123
ip_addr_t pending_address;
124
u16_t pending_port;
126
uint8_t timer_configured;
127
#endif
/* WITH_LWIP */
128
135
unsigned
short
message_id
;
136
141
unsigned
int
observe
;
142
143
coap_response_handler_t
response_handler
;
144
}
coap_context_t
;
145
153
static
inline
void
154
coap_register_response_handler
(
coap_context_t
*context,
155
coap_response_handler_t
handler) {
156
context->
response_handler
= handler;
157
}
158
166
inline
static
void
167
coap_register_option
(
coap_context_t
*ctx,
unsigned
char
type) {
168
coap_option_setb
(ctx->
known_options
, type);
169
}
170
171
177
unsigned
int
coap_adjust_basetime
(
coap_context_t
*ctx, coap_tick_t now);
178
180
coap_queue_t
*
coap_peek_next
(
coap_context_t
*context );
181
183
coap_queue_t
*
coap_pop_next
(
coap_context_t
*context );
184
186
coap_context_t
*
coap_new_context
(
const
coap_address_t *listen_addr);
187
196
static
inline
unsigned
short
197
coap_new_message_id
(
coap_context_t
*context) {
198
#ifndef WITH_CONTIKI
199
return
htons(++(context->
message_id
));
200
#else
/* WITH_CONTIKI */
201
return
uip_htons(++context->
message_id
);
202
#endif
203
}
204
205
/* CoAP stack context must be released with coap_free_context() */
206
void
coap_free_context
(
coap_context_t
*context );
207
208
219
coap_tid_t
coap_send_confirmed
(
coap_context_t
*context,
220
const
coap_address_t *
dst
,
221
coap_pdu_t
*pdu);
222
240
coap_pdu_t
*
coap_new_error_response
(
coap_pdu_t
*request,
241
unsigned
char
code,
242
coap_opt_filter_t
opts);
253
coap_tid_t
coap_send
(
coap_context_t
*context,
254
const
coap_address_t *
dst
,
255
coap_pdu_t
*pdu);
256
274
coap_tid_t
coap_send_error
(
coap_context_t
*context,
275
coap_pdu_t
*request,
276
const
coap_address_t *
dst
,
277
unsigned
char
code,
278
coap_opt_filter_t
opts);
279
291
coap_tid_t
292
coap_send_message_type
(
coap_context_t
*context,
293
const
coap_address_t *
dst
,
294
coap_pdu_t
*request,
295
unsigned
char
type);
308
coap_tid_t
coap_send_ack
(
coap_context_t
*context,
309
const
coap_address_t *
dst
,
310
coap_pdu_t
*request);
311
324
static
inline
coap_tid_t
325
coap_send_rst
(
coap_context_t
*context,
326
const
coap_address_t *
dst
,
327
coap_pdu_t
*request) {
328
return
coap_send_message_type
(context, dst, request,
COAP_MESSAGE_RST
);
329
}
330
332
coap_tid_t
coap_retransmit
(
coap_context_t
*context,
coap_queue_t
*node );
333
339
int
coap_read
(
coap_context_t
*context );
340
349
void
coap_transaction_id
(
const
coap_address_t *peer,
const
coap_pdu_t
*pdu,
350
coap_tid_t
*
id
);
351
369
int
coap_remove_from_queue
(
coap_queue_t
**queue,
370
coap_tid_t
id
,
371
coap_queue_t
**node);
372
383
inline
static
int
384
coap_remove_transaction
(
coap_queue_t
**queue,
coap_tid_t
id
) {
385
coap_queue_t
*node;
386
if
(!
coap_remove_from_queue
(queue,
id
, &node))
387
return
0;
388
389
coap_delete_node
(node);
390
return
1;
391
}
392
399
coap_queue_t
*
coap_find_transaction
(
coap_queue_t
*queue,
coap_tid_t
id
);
400
410
void
coap_cancel_all_messages
(
coap_context_t
*context,
411
const
coap_address_t *
dst
,
412
const
unsigned
char
*token,
413
size_t
token_length);
414
416
void
coap_dispatch
(
coap_context_t
*context );
417
419
int
coap_can_exit
(
coap_context_t
*context );
420
425
void
coap_ticks
(coap_tick_t *);
426
459
int
coap_option_check_critical
(
coap_context_t
*ctx,
460
coap_pdu_t
*pdu,
461
coap_opt_filter_t
unknown);
462
463
#ifdef __cplusplus
464
}
465
#endif
466
467
#endif
/* _COAP_NET_H_ */
Generated on Wed Feb 5 2014 15:10:20 for libcoap by
1.8.4