Mistake on this page?
Report an issue in GitHub or email us
QUECTEL_BG96_CellularStack.h
1 /*
2  * Copyright (c) 2017, Arm Limited and affiliates.
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 QUECTEL_BG96_CELLULARSTACK_H_
19 #define QUECTEL_BG96_CELLULARSTACK_H_
20 
21 #include "AT_CellularStack.h"
22 
23 namespace mbed {
24 
25 #define BG96_CREATE_SOCKET_TIMEOUT 150s
26 #define BG96_CLOSE_SOCKET_TIMEOUT 20s // TCP socket max timeout is >10sec
27 #define BG96_MAX_RECV_SIZE 1500
28 #define BG96_MAX_SEND_SIZE 1460
29 #define BG96_SOCKET_BIND_FAIL 556
30 
31 typedef enum {
32  URC_RECV,
33  URC_CLOSED,
34 } urc_type_t;
35 
37 public:
38  QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device);
39  virtual ~QUECTEL_BG96_CellularStack();
40 
41 protected: // NetworkStack
42 
43  virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
44 
46  nsapi_socket_t *handle, SocketAddress *address = 0);
47 
48  virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
49 
50 #ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
51  virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name);
52  virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC,
53  const char *interface_name = NULL);
55 #endif
56 
57 #if defined(MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET) && (MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET)
58  virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
59  int optname, const void *optval, unsigned optlen);
60 #endif
61 
62 protected: // AT_CellularStack
63 
64  virtual nsapi_error_t socket_close_impl(int sock_id);
65 
67 
69  const void *data, nsapi_size_t size);
70 
72  void *buffer, nsapi_size_t size);
73 
74 private:
75  // URC handler
76  void urc_qiurc(urc_type_t urc_type);
77  // URC handler for socket data being received
78  void urc_qiurc_recv();
79  // URC handler for socket being closed
80  void urc_qiurc_closed();
81 
82  void handle_open_socket_response(int &modem_connect_id, int &err, bool tlssocket);
83 
84 #if defined(MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET) && (MBED_CONF_NSAPI_OFFLOAD_TLSSOCKET)
85  nsapi_error_t set_to_modem_impl(const char *filename, const char *config, const char *data, size_t size);
86 #endif
87 
88 #ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
89  // URC handler for DNS query
90  void urc_qiurc_dnsgip();
91  // read DNS query result
92  bool read_dnsgip(SocketAddress &address, nsapi_version_t _dns_version);
93  hostbyname_cb_t _dns_callback;
94  nsapi_version_t _dns_version;
95 #endif
96 
97  uint8_t _tls_sec_level;
98 
99  /** Convert IP address to dotted string representation
100  *
101  * BG96 requires consecutive zeros so can't use get_ip_address or ip6tos directly.
102  *
103  * @param ip address
104  * @param dot buffer with size NSAPI_IPv6, where address is written zero terminated
105  */
106  void ip2dot(const SocketAddress &ip, char *dot);
107 };
108 } // namespace mbed
109 #endif /* QUECTEL_BG96_CELLULARSTACK_H_ */
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address)
Connects TCP socket to a remote host.
virtual nsapi_error_t create_socket_impl(CellularSocket *socket)
Implements modem specific AT command set for creating socket.
Class AT_CellularStack.
void * nsapi_socket_t
Opaque handle for network sockets.
Definition: nsapi_types.h:207
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog)
Listen for connections on a TCP socket.
virtual nsapi_error_t socket_close_impl(int sock_id)
Implements modem specific AT command set for socket closing.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:106
virtual nsapi_error_t gethostbyname_async_cancel(int id)
Cancels asynchronous hostname translation.
signed int nsapi_value_or_error_t
Type used to represent either a value or error.
Definition: nsapi_types.h:113
virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
Set stack-specific socket options.
SocketAddress class.
Definition: SocketAddress.h:36
virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
Translates a hostname to an IP address with specific version.
Class AT_CellularDevice.
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:99
Callback class based on template specialization.
Definition: Callback.h:53
virtual nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0)
Accepts a connection on a TCP socket.
Definition: ATHandler.h:46
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
Translates a hostname to multiple IP addresses (asynchronous)
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, const void *data, nsapi_size_t size)
Implements modem specific AT command set for sending data.
Class for sending AT commands and parsing AT responses.
Definition: ATHandler.h:70
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, void *buffer, nsapi_size_t size)
Implements modem specific AT command set for receiving data.
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.