Mbed OS Reference
Loading...
Searching...
No Matches
CellularNonIPSocket.h
1/* CellularNonIPSocket
2 * Copyright (c) 2015 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef CELLULARNONIPSOCKET_H
19#define CELLULARNONIPSOCKET_H
20
21#include "netsocket/Socket.h"
22#include "rtos/Mutex.h"
23#include "rtos/EventFlags.h"
24#include "Callback.h"
25#include "mbed_atomic.h"
26#include "mbed_toolchain.h"
27#include "ControlPlane_netif.h"
28#include "CellularContext.h"
29
30namespace mbed {
31
32/** \addtogroup NetSocket */
33/** @{*/
34
35/** Socket implementation for cellular Non-IP data delivery(NIDD).
36 * Relies on Control Plane CIoT EPS optimization feature,
37 * implemented in ControlPlane_netif class.
38 */
40public:
41 /** Destroy the socket.
42 *
43 * @note Closes socket if it's still open.
44 */
46
47 /** Creates a socket.
48 */
50
51 /** Opens a socket on the given cellular context.
52 *
53 * @param cellular_context Cellular PDP context over which this socket is sending and
54 * receiving data. The context has support for providing
55 * a control plane interface for data delivery.
56 * @return NSAPI_ERROR_OK on success
57 * NSAPI_ERROR_PARAMETER otherwise
58 */
60
61 /** Opens a socket that will use the given control plane interface for data delivery.
62 * Attaches the event as callback to the control plane interface.
63 *
64 * @param cp_netif Control plane interface for data delivery.
65 * @return NSAPI_ERROR_OK on success
66 * NSAPI_ERROR_PARAMETER otherwise
67 *
68 */
70
71 /** Closes socket
72 *
73 * @return NSAPI_ERROR_OK on success
74 * NSAPI_ERROR_NO_SOCKET otherwise
75 */
76
77 nsapi_error_t close() override;
78
79 /** Send data over a control plane cellular context.
80 *
81 * By default, send blocks until all data is sent. If socket is set to
82 * nonblocking or times out, a partial amount can be written.
83 * NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.
84 *
85 * @param data Buffer of data to be sent.
86 * @param size Size of the buffer in bytes.
87 * @return Number of sent bytes on success, negative error
88 * code on failure.
89 */
90 nsapi_size_or_error_t send(const void *data, nsapi_size_t size) override;
91
92 /** Receive data from a socket.
93 *
94 * By default, recv blocks until some data is received. If socket is set to
95 * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to
96 * indicate no data.
97 *
98 * @param data Pointer to buffer for received data.
99 * @param size Size of the buffer in bytes.
100 * @return Number of received bytes on success, negative error
101 * code on failure.
102 */
103 nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override;
104
105 /** @copydoc Socket::set_blocking
106 */
107 void set_blocking(bool blocking) override;
108
109 /** @copydoc Socket::set_timeout
110 */
111 void set_timeout(int timeout) override;
112
113 /** @copydoc Socket::sigio
114 */
115 void sigio(mbed::Callback<void()> func) override;
116
117 /// NOT APPLICABLE
118 nsapi_error_t connect(const SocketAddress &address) override;
119 /// NOT APPLICABLE
120 Socket *accept(nsapi_error_t *error = NULL) override;
121 /// NOT APPLICABLE
122 nsapi_error_t listen(int backlog = 1) override;
123 /// NOT APPLICABLE
124 nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen) override;
125 /// NOT APPLICABLE
126 nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen) override;
127 /// NOT APPLICABLE
129 /// NOT APPLICABLE
131 const void *data, nsapi_size_t size) override;
132 /// NOT APPLICABLE
134 void *data, nsapi_size_t size) override;
135 /// NOT APPLICABLE
137 const void *data, nsapi_size_t size,
138 nsapi_msghdr_t *control, nsapi_size_t control_size) override;
139 /// NOT APPLICABLE
141 void *data, nsapi_size_t size,
142 nsapi_msghdr_t *control, nsapi_size_t control_size) override;
143 /// NOT APPLICABLE
144 nsapi_error_t bind(const SocketAddress &address) override;
145
146protected:
147 void event();
148
149 uint32_t _timeout = osWaitForever;
150 mbed::Callback<void()> _event;
151 mbed::Callback<void()> _callback;
152 rtos::EventFlags _event_flag;
153 rtos::Mutex _lock;
154 uint8_t _readers = 0;
155 uint8_t _writers = 0;
157
158 // Event flags
159 static const int READ_FLAG = 0x1u;
160 static const int WRITE_FLAG = 0x2u;
161 static const int FINISHED_FLAG = 0x3u;
162
163 static ControlPlane_netif *_cp_netif; // there can be only one Non-IP socket
164 bool _opened = false;
165};
166
167/** @}*/
168} // namespace mbed
169
170#endif // CELLULARNONIPSOCKET_H
Cellular PDP context class.
Implements support for data transfer using Control Plane CIoT EPS optimization.
Abstract Socket interface.
SocketAddress class.
Definition: SocketAddress.h:37
Socket interface.
Definition: Socket.h:40
Callback class based on template specialization.
Definition: Callback.h:53
CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity.
Socket implementation for cellular Non-IP data delivery(NIDD).
~CellularNonIPSocket() override
Destroy the socket.
nsapi_size_or_error_t send(const void *data, nsapi_size_t size) override
Send data over a control plane cellular context.
nsapi_size_or_error_t sendto_control(const SocketAddress &address, const void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size) override
NOT APPLICABLE.
nsapi_error_t connect(const SocketAddress &address) override
NOT APPLICABLE.
nsapi_error_t bind(const SocketAddress &address) override
NOT APPLICABLE.
nsapi_error_t listen(int backlog=1) override
NOT APPLICABLE.
nsapi_error_t open(mbed::CellularContext *cellular_context)
Opens a socket on the given cellular context.
void sigio(mbed::Callback< void()> func) override
Register a callback on state change of the socket.
nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size) override
NOT APPLICABLE.
void set_blocking(bool blocking) override
Set blocking or non-blocking mode of the socket.
nsapi_error_t open(mbed::ControlPlane_netif *cp_netif)
Opens a socket that will use the given control plane interface for data delivery.
nsapi_size_or_error_t recvfrom_control(SocketAddress *address, void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size) override
NOT APPLICABLE.
void set_timeout(int timeout) override
Set timeout on blocking socket operations.
Socket * accept(nsapi_error_t *error=NULL) override
NOT APPLICABLE.
nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen) override
NOT APPLICABLE.
nsapi_error_t close() override
Closes socket.
nsapi_size_or_error_t recv(void *data, nsapi_size_t size) override
Receive data from a socket.
nsapi_size_or_error_t recvfrom(SocketAddress *address, void *data, nsapi_size_t size) override
NOT APPLICABLE.
nsapi_error_t getpeername(SocketAddress *address) override
NOT APPLICABLE.
CellularNonIPSocket()
Creates a socket.
nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen) override
NOT APPLICABLE.
Implements support for data transfer using Control Plane CIoT EPS optimization specified in 3GPP 23....
The EventFlags class is used to control event flags or wait for event flags other threads control.
Definition: EventFlags.h:53
The Mutex class is used to synchronize the execution of threads.
Definition: Mutex.h:70
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:153
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:146
#define CORE_UTIL_ATOMIC_FLAG_INIT
Initializer for a core_util_atomic_flag.
Definition: mbed_atomic.h:130
MBED_NORETURN void error(const char *format,...) MBED_PRINTF(1
To generate a fatal compile-time error, you can use the pre-processor error directive.
A lock-free, primitive atomic flag.
Definition: mbed_atomic.h:118
Header structure for control info.
Definition: nsapi_types.h:426