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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
AT_CellularContext.h
00001 /* 00002 * Copyright (c) 2018, 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 #ifndef AT_CELLULARCONTEXT_H_ 00018 #define AT_CELLULARCONTEXT_H_ 00019 00020 #include "CellularContext.h" 00021 #include "ATHandler.h" 00022 #include "Semaphore.h" 00023 #include "AT_CellularDevice.h" 00024 00025 const int MAX_APN_LENGTH = 63 + 1; 00026 00027 namespace mbed { 00028 00029 class AT_CellularContext : public CellularContext { 00030 public: 00031 AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0, bool cp_req = false, bool nonip_req = false); 00032 virtual ~AT_CellularContext(); 00033 00034 // from CellularInterface/NetworkInterface 00035 virtual nsapi_error_t set_blocking(bool blocking); 00036 virtual NetworkStack *get_stack(); 00037 virtual nsapi_error_t get_ip_address(SocketAddress *address); 00038 virtual const char *get_ip_address(); 00039 virtual char *get_interface_name(char *interface_name); 00040 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00041 virtual nsapi_error_t connect(); 00042 virtual nsapi_error_t disconnect(); 00043 virtual nsapi_connection_status_t get_connection_status() const; 00044 virtual bool is_connected(); 00045 // from CellularInterface 00046 virtual void set_plmn(const char *plmn); 00047 virtual void set_sim_pin(const char *sim_pin); 00048 virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0, 00049 const char *pwd = 0); 00050 virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0); 00051 virtual nsapi_error_t get_netmask(SocketAddress *address); 00052 virtual const char *get_netmask(); 00053 virtual nsapi_error_t get_gateway(SocketAddress *address); 00054 virtual const char *get_gateway(); 00055 00056 // from CellularContext 00057 virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t ¶ms_list); 00058 virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports, 00059 CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate); 00060 virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer); 00061 virtual nsapi_error_t set_device_ready(); 00062 virtual nsapi_error_t set_sim_ready(); 00063 virtual nsapi_error_t register_to_network(); 00064 virtual nsapi_error_t attach_to_network(); 00065 virtual void set_file_handle(FileHandle *fh); 00066 #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) 00067 virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false); 00068 #endif // #if DEVICE_SERIAL 00069 virtual void enable_hup(bool enable); 00070 00071 virtual ControlPlane_netif *get_cp_netif(); 00072 00073 AT_CellularDevice *get_device() const; 00074 00075 ATHandler &get_at_handler(); 00076 protected: 00077 virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr); 00078 00079 /** Does the authentication for the PDP Context if user name and password are provided. 00080 * Can be overridden by the modem target if 3GPP default implementation if not an option 00081 * 00082 * @return NSAPI_ERROR_OK if no credentials provided or authentication was successful 00083 * NSAPI_ERROR_AUTH_FAILURE if authentication failed 00084 * NSAPI_ERROR_DEVICE_ERROR if communication with the modemm failed 00085 */ 00086 virtual nsapi_error_t do_user_authentication(); 00087 00088 /** Activates PDP context or in PPP mode opens data channel. 00089 * Can be overridden by the modem target if 3GPP default implementation if not an option 00090 */ 00091 virtual void do_connect(); 00092 00093 /** Get the operation specific timeout. Used in synchronous mode when setting the maximum 00094 * waiting time. Modem specific implementation can override this to provide different timeouts. 00095 * 00096 * @param op current operation 00097 * @return timeout in milliseconds 00098 */ 00099 virtual uint32_t get_timeout_for_operation(ContextOperation op) const; 00100 00101 virtual nsapi_error_t activate_non_ip_context(); 00102 virtual nsapi_error_t setup_control_plane_opt(); 00103 virtual void deactivate_non_ip_context(); 00104 virtual void deactivate_ip_context(); 00105 virtual void set_disconnect(); 00106 virtual void deactivate_context(); 00107 virtual bool get_context(); 00108 AT_CellularDevice::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type); 00109 bool set_new_context(int cid); 00110 private: 00111 #if NSAPI_PPP_AVAILABLE 00112 nsapi_error_t open_data_channel(); 00113 void ppp_status_cb(nsapi_event_t ev, intptr_t ptr); 00114 void ppp_disconnected(); 00115 #endif // #if NSAPI_PPP_AVAILABLE 00116 nsapi_error_t do_activate_context(); 00117 virtual void activate_context(); 00118 nsapi_error_t find_and_activate_context(); 00119 nsapi_error_t activate_ip_context(); 00120 void check_and_deactivate_context(); 00121 void delete_current_context(); 00122 nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op); 00123 void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt); 00124 virtual void do_connect_with_retry(); 00125 void do_disconnect(); 00126 void set_cid(int cid); 00127 private: 00128 ContextOperation _current_op; 00129 FileHandle *_fh; 00130 rtos::Semaphore _semaphore; 00131 rtos::Semaphore _cp_opt_semaphore; 00132 00133 protected: 00134 char _found_apn[MAX_APN_LENGTH]; 00135 // flag indicating if CP was requested to be setup 00136 bool _cp_req; 00137 bool _is_connected; 00138 00139 protected: 00140 ATHandler &_at; 00141 }; 00142 00143 } // namespace mbed 00144 00145 #endif // AT_CELLULARCONTEXT_H_
Generated on Tue Jul 12 2022 13:54:02 by
