Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QUECTEL_BG96_CellularStack.h Source File

QUECTEL_BG96_CellularStack.h

00001 /*
00002  * Copyright (c) 2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef QUECTEL_BG96_CELLULARSTACK_H_
00019 #define QUECTEL_BG96_CELLULARSTACK_H_
00020 
00021 #include "AT_CellularStack.h"
00022 
00023 namespace mbed {
00024 
00025 #define BG96_SOCKET_MAX 12
00026 #define BG96_CREATE_SOCKET_TIMEOUT 150000 //150 seconds
00027 #define BG96_CLOSE_SOCKET_TIMEOUT 20000 // TCP socket max timeout is >10sec
00028 #define BG96_MAX_RECV_SIZE 1500
00029 #define BG96_MAX_SEND_SIZE 1460
00030 #define BG96_SOCKET_BIND_FAIL 556
00031 
00032 typedef enum {
00033     URC_RECV,
00034     URC_CLOSED,
00035 } urc_type_t;
00036 
00037 class QUECTEL_BG96_CellularStack : public AT_CellularStack {
00038 public:
00039     QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device);
00040     virtual ~QUECTEL_BG96_CellularStack();
00041 
00042 protected: // NetworkStack
00043 
00044     virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
00045 
00046     virtual nsapi_error_t socket_accept(nsapi_socket_t server,
00047                                         nsapi_socket_t *handle, SocketAddress *address = 0);
00048 
00049     virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
00050 
00051 #ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
00052     virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name);
00053     virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC ,
00054                                                        const char *interface_name = NULL);
00055     virtual nsapi_error_t gethostbyname_async_cancel(int id);
00056 #endif
00057 
00058     virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
00059                                      int optname, const void *optval, unsigned optlen);
00060 
00061 protected: // AT_CellularStack
00062 
00063     virtual int get_max_socket_count();
00064 
00065     virtual bool is_protocol_supported(nsapi_protocol_t protocol);
00066 
00067     virtual nsapi_error_t socket_close_impl(int sock_id);
00068 
00069     virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
00070 
00071     virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
00072                                                      const void *data, nsapi_size_t size);
00073 
00074     virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
00075                                                        void *buffer, nsapi_size_t size);
00076 
00077 private:
00078     // URC handler
00079     void urc_qiurc(urc_type_t urc_type);
00080     // URC handler for socket data being received
00081     void urc_qiurc_recv();
00082     // URC handler for socket being closed
00083     void urc_qiurc_closed();
00084 
00085     void handle_open_socket_response(int &modem_connect_id, int &err, bool tlssocket);
00086 
00087     nsapi_error_t set_to_modem_impl(const char *filename, const char *config, const char *data, size_t size);
00088 
00089 #ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
00090     // URC handler for DNS query
00091     void urc_qiurc_dnsgip();
00092     // read DNS query result
00093     bool read_dnsgip(SocketAddress &address, nsapi_version_t _dns_version);
00094     hostbyname_cb_t _dns_callback;
00095     nsapi_version_t _dns_version;
00096 #endif
00097 
00098     uint8_t _tls_sec_level;
00099 
00100     /** Convert IP address to dotted string representation
00101      *
00102      *  BG96 requires consecutive zeros so can't use get_ip_address or ip6tos directly.
00103      *
00104      *  @param ip address
00105      *  @param dot buffer with size NSAPI_IPv6, where address is written zero terminated
00106      */
00107     void ip2dot(const SocketAddress &ip, char *dot);
00108 };
00109 } // namespace mbed
00110 #endif /* QUECTEL_BG96_CELLULARSTACK_H_ */