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 virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto); 00050 00051 virtual nsapi_error_t socket_close(nsapi_socket_t handle); 00052 00053 virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address); 00054 00055 virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog); 00056 00057 virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address); 00058 00059 virtual nsapi_error_t socket_accept(nsapi_socket_t server, 00060 nsapi_socket_t *handle, SocketAddress *address=0); 00061 00062 virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, 00063 const void *data, nsapi_size_t size); 00064 00065 virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, 00066 void *data, nsapi_size_t size); 00067 00068 virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, 00069 const void *data, nsapi_size_t size); 00070 00071 virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, 00072 void *buffer, nsapi_size_t size); 00073 00074 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data); 00075 00076 protected: 00077 00078 class CellularSocket 00079 { 00080 public: 00081 // Socket id from cellular device 00082 int id; 00083 // Being connected means remote ip address and port are set 00084 bool connected; 00085 nsapi_protocol_t proto; 00086 SocketAddress remoteAddress; 00087 SocketAddress localAddress; 00088 void (*_cb)(void *); 00089 void *_data; 00090 bool created; 00091 bool rx_avail; // used to synchronize reading from modem 00092 }; 00093 00094 /** 00095 * Gets maximum number of sockets modem supports 00096 */ 00097 virtual int get_max_socket_count() = 0; 00098 00099 /** 00100 * Gets maximum packet size 00101 */ 00102 virtual int get_max_packet_size() = 0; 00103 00104 /** 00105 * Checks if modem supports the given protocol 00106 * 00107 * @param protocol Protocol type 00108 */ 00109 virtual bool is_protocol_supported(nsapi_protocol_t protocol) = 0; 00110 00111 /** 00112 * Implements modem specific AT command set for socket closing 00113 * 00114 * @param sock_id Socket id 00115 */ 00116 virtual nsapi_error_t socket_close_impl(int sock_id) = 0; 00117 00118 /** 00119 * Implements modem specific AT command set for creating socket 00120 * 00121 * @param socket Cellular socket handle 00122 */ 00123 virtual nsapi_error_t create_socket_impl(CellularSocket *socket) = 0; 00124 00125 /** 00126 * Implements modem specific AT command set for sending data 00127 * 00128 * @param socket Cellular socket handle 00129 * @param address The SocketAddress of the remote host 00130 * @param data Buffer of data to send to the host 00131 * @param size Size of the buffer in bytes 00132 * @return Number of sent bytes on success, negative error 00133 * code on failure 00134 */ 00135 virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, 00136 const void *data, nsapi_size_t size) = 0; 00137 00138 /** 00139 * Implements modem specific AT command set for receiving data 00140 * 00141 * @param socket Socket handle 00142 * @param address Destination for the source address or NULL 00143 * @param buffer Destination buffer for data received from the host 00144 * @param size Size of the buffer in bytes 00145 * @return Number of received bytes on success, negative error 00146 * code on failure 00147 */ 00148 virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, 00149 void *buffer, nsapi_size_t size) = 0; 00150 00151 // socket container 00152 CellularSocket **_socket; 00153 00154 // number of socket slots allocated in socket container 00155 int _socket_count; 00156 00157 // IP address 00158 char _ip[PDP_IPV6_SIZE]; 00159 00160 // PDP context id 00161 int _cid; 00162 00163 // stack type from PDP context 00164 nsapi_ip_stack_t _stack_type; 00165 }; 00166 00167 } // namespace mbed 00168 00169 #endif // AT_CELLULAR_STACK_H_
Generated on Tue Jul 12 2022 14:23:22 by
