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_toolchain.h"
25 #include "ControlPlane_netif.h"
26 #include "CellularContext.h"
27 
28 namespace mbed {
29 
30 /** \addtogroup netsocket */
31 /** @{*/
32 
33 /** Socket implementation for cellular Non-IP data delivery(NIDD).
34  * Relies on Control Plane CIoT EPS optimization feature,
35  * implemented in ControlPlane_netif class.
36  */
37 class CellularNonIPSocket : public Socket {
38 public:
39  /** Destroy the socket.
40  *
41  * @note Closes socket if it's still open.
42  */
43  virtual ~CellularNonIPSocket();
44 
45  /** Creates a socket.
46  */
48 
49  /** Opens a socket on the given cellular context.
50  *
51  * @param cellular_context Cellular PDP context over which this socket is sending and
52  * receiving data. The context has support for providing
53  * a control plane interface for data delivery.
54  * @return NSAPI_ERROR_OK on success
55  * NSAPI_ERROR_PARAMETER otherwise
56  */
57  virtual nsapi_error_t open(mbed::CellularContext *cellular_context);
58 
59  /** Opens a socket that will use the given control plane interface for data delivery.
60  * Attaches the event as callback to the control plane interface.
61  *
62  * @param cp_netif Control plane interface for data delivery.
63  * @return NSAPI_ERROR_OK on success
64  * NSAPI_ERROR_PARAMETER otherwise
65  *
66  */
67  virtual nsapi_error_t open(mbed::ControlPlane_netif *cp_netif);
68 
69  /** Closes socket
70  *
71  * @return NSAPI_ERROR_OK on success
72  * NSAPI_ERROR_NO_SOCKET otherwise
73  */
74 
75  virtual nsapi_error_t close();
76 
77  /** Send data over a control plane cellular context.
78  *
79  * By default, send blocks until all data is sent. If socket is set to
80  * nonblocking or times out, a partial amount can be written.
81  * NSAPI_ERROR_WOULD_BLOCK is returned if no data was written.
82  *
83  * @param data Buffer of data to be sent.
84  * @param size Size of the buffer in bytes.
85  * @return Number of sent bytes on success, negative error
86  * code on failure.
87  */
88  virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size);
89 
90  /** Receive data from a socket.
91  *
92  * By default, recv blocks until some data is received. If socket is set to
93  * nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK can be returned to
94  * indicate no data.
95  *
96  * @param data Pointer to buffer for received data.
97  * @param size Size of the buffer in bytes.
98  * @return Number of received bytes on success, negative error
99  * code on failure.
100  */
101  virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
102 
103  /** @copydoc Socket::set_blocking
104  */
105  virtual void set_blocking(bool blocking);
106 
107  /** @copydoc Socket::set_timeout
108  */
109  virtual void set_timeout(int timeout);
110 
111  /** @copydoc Socket::sigio
112  */
113  virtual void sigio(mbed::Callback<void()> func);
114 
115  /// NOT APPLICABLE
116  virtual nsapi_error_t connect(const SocketAddress &address);
117  /// NOT APPLICABLE
118  virtual Socket *accept(nsapi_error_t *error = NULL);
119  /// NOT APPLICABLE
120  virtual nsapi_error_t listen(int backlog = 1);
121  /// NOT APPLICABLE
122  virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen);
123  /// NOT APPLICABLE
124  virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen);
125  /// NOT APPLICABLE
126  virtual nsapi_error_t getpeername(SocketAddress *address);
127  /// NOT APPLICABLE
128  virtual nsapi_size_or_error_t sendto(const SocketAddress &address,
129  const void *data, nsapi_size_t size);
130  /// NOT APPLICABLE
132  void *data, nsapi_size_t size);
133  /// NOT APPLICABLE
134  virtual nsapi_error_t bind(const SocketAddress &address);
135 
136 protected:
137  virtual void event();
138 
139  uint32_t _timeout;
140  mbed::Callback<void()> _event;
141  mbed::Callback<void()> _callback;
142  rtos::EventFlags _event_flag;
143  rtos::Mutex _lock;
144  uint8_t _readers;
145  uint8_t _writers;
146  volatile unsigned _pending;
147 
148  // Event flags
149  static const int READ_FLAG = 0x1u;
150  static const int WRITE_FLAG = 0x2u;
151  static const int FINISHED_FLAG = 0x3u;
152 
153  ControlPlane_netif *_cp_netif;
154  bool _opened;
155 };
156 
157 /** @}*/
158 } // namespace mbed
159 
160 #endif // CELLULARNONIPSOCKET_H
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, void *data, nsapi_size_t size)
NOT APPLICABLE.
Implements support for data transfer using Control Plane CIoT EPS optimization specified in 3GPP 23...
virtual nsapi_error_t connect(const SocketAddress &address)
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:51
CellularNonIPSocket()
Creates a socket.
CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity...
Implements support for data transfer using Control Plane CIoT EPS optimization.
virtual nsapi_error_t open(mbed::CellularContext *cellular_context)
Opens a socket on the given cellular context.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
virtual nsapi_error_t listen(int backlog=1)
NOT APPLICABLE.
virtual void set_blocking(bool blocking)
Set blocking or non-blocking mode of the socket.
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:106
Abstract Socket interface.
virtual Socket * accept(nsapi_error_t *error=NULL)
NOT APPLICABLE.
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size)
Send data over a control plane cellular context.
virtual nsapi_error_t bind(const SocketAddress &address)
NOT APPLICABLE.
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size)
NOT APPLICABLE.
Cellular PDP context class.
virtual nsapi_error_t getpeername(SocketAddress *address)
NOT APPLICABLE.
SocketAddress class.
Definition: SocketAddress.h:35
The Mutex class is used to synchronize the execution of threads.
Definition: Mutex.h:68
virtual nsapi_error_t close()
Closes socket.
virtual void sigio(mbed::Callback< void()> func)
Register a callback on state change of the socket.
Socket interface.
Definition: Socket.h:39
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:99
virtual void set_timeout(int timeout)
Set timeout on blocking socket operations.
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size)
Receive data from a socket.
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen)
NOT APPLICABLE.
virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen)
NOT APPLICABLE.
Callback class based on template specialization.
Definition: Callback.h:39
virtual ~CellularNonIPSocket()
Destroy the socket.
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.