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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.