Mistake on this page?
Report an issue in GitHub or email us
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 
30 namespace 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  */
39 class CellularNonIPSocket : public Socket {
40 public:
41  /** Destroy the socket.
42  *
43  * @note Closes socket if it's still open.
44  */
45  ~CellularNonIPSocket() override;
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  */
59  nsapi_error_t open(mbed::CellularContext *cellular_context);
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
128  nsapi_error_t getpeername(SocketAddress *address) override;
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
136  nsapi_error_t bind(const SocketAddress &address) override;
137 
138 protected:
139  void event();
140 
141  uint32_t _timeout = osWaitForever;
142  mbed::Callback<void()> _event;
143  mbed::Callback<void()> _callback;
144  rtos::EventFlags _event_flag;
145  rtos::Mutex _lock;
146  uint8_t _readers = 0;
147  uint8_t _writers = 0;
149 
150  // Event flags
151  static const int READ_FLAG = 0x1u;
152  static const int WRITE_FLAG = 0x2u;
153  static const int FINISHED_FLAG = 0x3u;
154 
155  static ControlPlane_netif *_cp_netif; // there can be only one Non-IP socket
156  bool _opened = false;
157 };
158 
159 /** @}*/
160 } // namespace mbed
161 
162 #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:140
A lock-free, primitive atomic flag.
Definition: mbed_atomic.h:117
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:151
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:37
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:40
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:144
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:53
Definition: ATHandler.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:129
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.