takashi kadono / Mbed OS Nucleo446_SSD1331

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AT_CellularNetwork.h Source File

AT_CellularNetwork.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_NETWORK_H_
00019 #define AT_CELLULAR_NETWORK_H_
00020 
00021 #include "CellularNetwork.h"
00022 #include "AT_CellularBase.h"
00023 #include "NetworkStack.h"
00024 
00025 namespace mbed {
00026 
00027 #define AT_NETWORK_TRIALS 5
00028 
00029 /**
00030  *  Class AT_CellularNetwork
00031  *
00032  *  Class for connecting to a network and getting information from it.
00033  */
00034 class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase {
00035 
00036 public:
00037 
00038     AT_CellularNetwork(ATHandler &atHandler);
00039     virtual ~AT_CellularNetwork();
00040     // declare friend so it can access stack
00041     friend class AT_CellularDevice;
00042 
00043 public: // NetworkInterface
00044 
00045     virtual nsapi_error_t set_credentials(const char *apn,
00046                                           const char *username = 0, const char *password = 0);
00047 
00048     virtual nsapi_error_t set_credentials(const char *apn, AuthenticationType type,
00049                                           const char *username = 0, const char *password = 0);
00050 
00051     virtual nsapi_error_t connect(const char *apn,
00052                                   const char *username = 0, const char *password = 0);
00053 
00054     virtual nsapi_error_t connect();
00055 
00056     virtual nsapi_error_t disconnect();
00057 
00058 protected:
00059     virtual NetworkStack *get_stack();
00060 
00061 public: // CellularNetwork
00062     virtual nsapi_error_t init();
00063 
00064     virtual nsapi_error_t activate_context();
00065 
00066     virtual nsapi_error_t set_registration(const char *plmn = 0);
00067 
00068     virtual nsapi_error_t get_network_registering_mode(NWRegisteringMode &mode);
00069 
00070     virtual nsapi_error_t get_registration_status(RegistrationType type, RegistrationStatus &status);
00071 
00072     virtual nsapi_error_t set_attach(int timeout = 10 * 1000);
00073 
00074     virtual nsapi_error_t get_attach(AttachStatus &status);
00075 
00076     virtual nsapi_error_t detach();
00077 
00078     virtual nsapi_error_t get_rate_control(CellularNetwork::RateControlExceptionReports &reports,
00079                                            CellularNetwork::RateControlUplinkTimeUnit &time_unit, int &uplink_rate);
00080 
00081     virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer);
00082 
00083     virtual void attach(Callback<void(nsapi_event_t, intptr_t)> status_cb);
00084 
00085     virtual nsapi_connection_status_t get_connection_status() const;
00086 
00087     virtual nsapi_error_t set_blocking(bool blocking);
00088 
00089     virtual const char *get_ip_address();
00090 
00091     virtual nsapi_error_t set_access_technology(RadioAccessTechnology rat);
00092     virtual nsapi_error_t get_access_technology(RadioAccessTechnology &rat);
00093 
00094     virtual nsapi_error_t scan_plmn(operList_t &operators, int &ops_count);
00095 
00096     virtual nsapi_error_t set_ciot_optimization_config(Supported_UE_Opt supported_opt,
00097                                                        Preferred_UE_Opt preferred_opt);
00098 
00099     virtual nsapi_error_t get_ciot_optimization_config(Supported_UE_Opt &supported_opt,
00100                                                        Preferred_UE_Opt &preferred_opt);
00101 
00102     virtual nsapi_error_t set_stack_type(nsapi_ip_stack_t stack_type);
00103 
00104     virtual nsapi_ip_stack_t get_stack_type();
00105 
00106     virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list);
00107 
00108     virtual nsapi_error_t get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp);
00109 
00110     virtual nsapi_error_t get_signal_quality(int &rssi, int &ber);
00111 
00112     virtual nsapi_error_t get_cell_id(int &cell_id);
00113 
00114     virtual int get_3gpp_error();
00115 
00116     virtual nsapi_error_t get_operator_params(int &format, operator_t &operator_params);
00117 
00118     virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on);
00119 
00120     virtual nsapi_error_t get_operator_names(operator_names_list &op_names);
00121 protected:
00122 
00123     /** Check if modem supports the given stack type.
00124      *
00125      *  @return true if supported
00126      */
00127     virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack);
00128 
00129     /** Check if modem supports given registration type.
00130      *
00131      *  @param reg_type enum RegistrationType
00132      *  @return         mode supported on given reg_type as per 3GPP TS 27.007, 0 when unsupported
00133      */
00134     enum RegistrationMode {
00135         RegistrationModeDisable = 0,
00136         RegistrationModeEnable, // <stat>
00137         RegistrationModeLAC, // <stat>[,<[lac>,]<[ci>],[<AcT>],[<rac>]]
00138     };
00139     virtual RegistrationMode has_registration(RegistrationType reg_type);
00140 
00141     /** Sets access technology to be scanned. Modem specific implementation.
00142      *
00143      *  @param op_rat Access technology
00144      *
00145      *  @return       zero on success
00146      */
00147     virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat);
00148 
00149     /** APN user authentication
00150      *
00151      *  @return       NSAPI_ERROR_OK on success
00152      *                NSAPI_ERROR_UNSUPPORTED on authentication not supported by cellular device
00153      *                NSAPI_ERROR_AUTH_FAILURE on authentication to network failed
00154      */
00155     virtual nsapi_error_t do_user_authentication();
00156 private:
00157     //  "NO CARRIER" urc
00158     void urc_no_carrier();
00159     void urc_creg();
00160     void urc_cereg();
00161     void urc_cgreg();
00162     void urc_cgev();
00163 
00164     nsapi_ip_stack_t string_to_stack_type(const char *pdp_type);
00165 
00166     void free_credentials();
00167 
00168     nsapi_error_t open_data_channel();
00169     bool get_context();
00170     bool set_new_context(int cid);
00171 
00172     nsapi_error_t delete_current_context();
00173 
00174     void read_reg_params_and_compare(RegistrationType type);
00175     void read_reg_params(RegistrationType type, RegistrationStatus &reg_status, int &lac, int &cell_id, int &act);
00176     // calls network callback only if status was changed, updates local connection status
00177     void call_network_cb(nsapi_connection_status_t status);
00178 #if NSAPI_PPP_AVAILABLE
00179     void ppp_status_cb(nsapi_event_t, intptr_t);
00180 #endif
00181 
00182 protected:
00183     NetworkStack *_stack;
00184     char *_apn;
00185     char *_uname;
00186     char *_pwd;
00187     nsapi_ip_stack_t _ip_stack_type_requested;
00188     nsapi_ip_stack_t _ip_stack_type;
00189     int _cid;
00190     Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
00191     RadioAccessTechnology _op_act;
00192     AuthenticationType _authentication_type;
00193     int _cell_id;
00194     nsapi_connection_status_t _connect_status;
00195     bool _new_context_set;
00196     bool _is_context_active;
00197     RegistrationStatus _reg_status;
00198     RadioAccessTechnology _current_act;
00199     mbed::Callback<void()> _urc_funcs[C_MAX];
00200 };
00201 
00202 } // namespace mbed
00203 
00204 #endif // AT_CELLULAR_NETWORK_H_