Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
AT_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 AT_CELLULAR_STACK_H_ 00019 #define AT_CELLULAR_STACK_H_ 00020 00021 #include "AT_CellularBase.h" 00022 #include "NetworkStack.h" 00023 00024 namespace mbed { 00025 00026 // <PDP_addr_1> and <PDP_addr_2>: each is a string type that identifies the MT in the address space applicable to the PDP. 00027 // The string is given as dot-separated numeric (0-255) parameter of the form: 00028 // a1.a2.a3.a4 for IPv4 and 00029 // a1.a2.a3.a4.a5.a6.a7.a8.a9.a10.a11.a12.a13.a14.a15.a16 for IPv6. 00030 #define PDP_IPV6_SIZE 63+1 00031 00032 /** 00033 * Class AT_CellularStack. 00034 * 00035 * Implements NetworkStack and introduces interface for modem specific stack implementations. 00036 */ 00037 class AT_CellularStack : public NetworkStack, public AT_CellularBase 00038 { 00039 00040 public: 00041 AT_CellularStack(ATHandler &at, int cid, nsapi_ip_stack_t stack_type); 00042 virtual ~AT_CellularStack(); 00043 00044 public: // NetworkStack 00045 00046 virtual const char *get_ip_address(); 00047 protected: // NetworkStack 00048 00049 /** 00050 * Modem specific socket stack initialization 00051 * 00052 * @return 0 on success 00053 */ 00054 virtual nsapi_error_t socket_stack_init(); 00055 00056 virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto); 00057 00058 virtual nsapi_error_t socket_close(nsapi_socket_t handle); 00059 00060 virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address); 00061 00062 virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog); 00063 00064 virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address); 00065 00066 virtual nsapi_error_t socket_accept(nsapi_socket_t server, 00067 nsapi_socket_t *handle, SocketAddress *address=0); 00068 00069 virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, 00070 const void *data, nsapi_size_t size); 00071 00072 virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, 00073 void *data, nsapi_size_t size); 00074 00075 virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, 00076 const void *data, nsapi_size_t size); 00077 00078 virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, 00079 void *buffer, nsapi_size_t size); 00080 00081 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data); 00082 00083 protected: 00084 00085 class CellularSocket 00086 { 00087 public: 00088 // Socket id from cellular device 00089 int id; 00090 // Being connected means remote ip address and port are set 00091 bool connected; 00092 nsapi_protocol_t proto; 00093 SocketAddress remoteAddress; 00094 SocketAddress localAddress; 00095 void (*_cb)(void *); 00096 void *_data; 00097 bool created; // socket has been created on modem stack 00098 bool started; // socket has been opened on modem stack 00099 bool tx_ready; // socket is ready for sending on modem stack 00100 bool rx_avail; // socket has data for reading on modem stack 00101 }; 00102 00103 /** 00104 * Gets maximum number of sockets modem supports 00105 */ 00106 virtual int get_max_socket_count() = 0; 00107 00108 /** 00109 * Gets maximum packet size 00110 */ 00111 virtual int get_max_packet_size() = 0; 00112 00113 /** 00114 * Checks if modem supports the given protocol 00115 * 00116 * @param protocol Protocol type 00117 */ 00118 virtual bool is_protocol_supported(nsapi_protocol_t protocol) = 0; 00119 00120 /** 00121 * Implements modem specific AT command set for socket closing 00122 * 00123 * @param sock_id Socket id 00124 */ 00125 virtual nsapi_error_t socket_close_impl(int sock_id) = 0; 00126 00127 /** 00128 * Implements modem specific AT command set for creating socket 00129 * 00130 * @param socket Cellular socket handle 00131 */ 00132 virtual nsapi_error_t create_socket_impl(CellularSocket *socket) = 0; 00133 00134 /** 00135 * Implements modem specific AT command set for sending data 00136 * 00137 * @param socket Cellular socket handle 00138 * @param address The SocketAddress of the remote host 00139 * @param data Buffer of data to send to the host 00140 * @param size Size of the buffer in bytes 00141 * @return Number of sent bytes on success, negative error 00142 * code on failure 00143 */ 00144 virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, 00145 const void *data, nsapi_size_t size) = 0; 00146 00147 /** 00148 * Implements modem specific AT command set for receiving data 00149 * 00150 * @param socket Socket handle 00151 * @param address Destination for the source address or NULL 00152 * @param buffer Destination buffer for data received from the host 00153 * @param size Size of the buffer in bytes 00154 * @return Number of received bytes on success, negative error 00155 * code on failure 00156 */ 00157 virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, 00158 void *buffer, nsapi_size_t size) = 0; 00159 00160 // socket container 00161 CellularSocket **_socket; 00162 00163 // number of socket slots allocated in socket container 00164 int _socket_count; 00165 00166 // IP address 00167 char _ip[PDP_IPV6_SIZE]; 00168 00169 // PDP context id 00170 int _cid; 00171 00172 // stack type from PDP context 00173 nsapi_ip_stack_t _stack_type; 00174 }; 00175 00176 } // namespace mbed 00177 00178 #endif // AT_CELLULAR_STACK_H_
Generated on Tue Jul 12 2022 12:43:34 by
