Dawn Framework 1.0
Universal data acquisition framework for embedded systems
transport.hxx
1// dawn/src/proto/wakaama/transport.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "internal.hxx"
9
10#include <netinet/in.h>
11#include <sys/socket.h>
12#include <vector>
13
14#ifdef CONFIG_DAWN_PROTO_WAKAAMA_DTLS_PSK
15extern "C"
16{
17# include <tinydtls/dtls.h>
18}
19#endif
20
21namespace dawn
22{
23namespace wakaama_internal
24{
30{
31public:
35 {
36 Connection *next;
37 int sock;
38 uint16_t securityInstanceId;
39 const uint8_t *pskIdentity;
40 size_t pskIdentityLen;
41 const uint8_t *pskKey;
42 size_t pskKeyLen;
43 sockaddr_storage addr;
44 socklen_t addrLen;
45#ifdef CONFIG_DAWN_PROTO_WAKAAMA_DTLS_PSK
46 session_t dtlsSession;
47 dtls_context_t *dtlsContext;
48 time_t lastSend;
49 bool dtls;
50#endif
51 };
52
55 explicit Transport(CProtoWakaama &owner);
56
59 ~Transport();
60
64
67 int openSocket();
68
71 int initDtls();
72
75 void destroyDtls();
76
80
83 void thread();
84
87 Connection *connectServer(uint16_t securityInstanceId);
88
91 Connection *findConnection(const void *addr, size_t addrLen);
92
95 void handlePacket(Connection *conn, uint8_t *buffer, size_t length);
96
99 void closeConnection(Connection *conn);
100
101private:
104 bool receiveOne(uint8_t *buffer, size_t capacity);
105
106 CProtoWakaama &owner;
107 Connection *connections;
108 std::vector<Connection *> connectionPool;
109 int sockfd;
110#ifdef CONFIG_DAWN_PROTO_WAKAAMA_DTLS_PSK
111 dtls_context_t *dtlsContext;
112 dtls_handler_t dtlsHandler;
113#endif
114};
115
116} // namespace wakaama_internal
117} // namespace dawn
Wakaama LwM2M client protocol implementation.
Definition wakaama.hxx:52
UDP and optional DTLS transport used by the Wakaama client runtime.
Definition transport.hxx:30
void closeAllConnections()
Close every active server connection.
int openSocket()
Open and bind the local UDP socket.
void handlePacket(Connection *conn, uint8_t *buffer, size_t length)
Deliver one received packet into the Wakaama runtime.
~Transport()
Close sockets, DTLS state, and connection-pool allocations.
Definition transport.cxx:73
Connection * findConnection(const void *addr, size_t addrLen)
Find an active connection by peer address.
int initDtls()
Initialize optional shared DTLS context state.
void destroyDtls()
Destroy optional shared DTLS context state.
void closeConnection(Connection *conn)
Close one active server connection.
Connection * connectServer(uint16_t securityInstanceId)
Connect to the server referenced by a Security object instance.
int initConnectionPool()
Allocate the fixed connection pool used by Wakaama callbacks.
Definition transport.cxx:92
void thread()
Run the transport receive loop.
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Runtime state for one remote LwM2M server connection.
Definition transport.hxx:35