Mistake on this page?
Report an issue in GitHub or email us
AT_CellularContext.h
1 /*
2  * Copyright (c) 2018, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef AT_CELLULARCONTEXT_H_
18 #define AT_CELLULARCONTEXT_H_
19 
20 #include "CellularContext.h"
21 #include "AT_CellularBase.h"
22 #include "Semaphore.h"
23 
24 const int MAX_APN_LENGTH = 63 + 1;
25 
26 namespace mbed {
27 
29 public:
30  AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0, bool cp_req = false, bool nonip_req = false);
31  virtual ~AT_CellularContext();
32 
33 // from CellularBase/NetworkInterface
34  virtual nsapi_error_t set_blocking(bool blocking);
35  virtual NetworkStack *get_stack();
36  virtual const char *get_ip_address();
37  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
38  virtual nsapi_error_t connect();
39  virtual nsapi_error_t disconnect();
40  virtual nsapi_connection_status_t get_connection_status() const;
41  virtual bool is_connected();
42  // from CellularBase
43  virtual void set_plmn(const char *plmn);
44  virtual void set_sim_pin(const char *sim_pin);
45  virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
46  const char *pwd = 0);
47  virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0);
48  virtual const char *get_netmask();
49  virtual const char *get_gateway();
50 
51 // from CellularContext
53  virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports,
54  CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate);
55  virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer);
57  virtual nsapi_error_t set_sim_ready();
60  virtual void set_file_handle(FileHandle *fh);
61 #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
62  virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false);
63 #endif // #if DEVICE_SERIAL
64  virtual void enable_hup(bool enable);
65 
67 
68 protected:
69  virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr);
70 
71  /** Does the authentication for the PDP Context if user name and password are provided.
72  * Can be overridden by the modem target if 3GPP default implementation if not an option
73  *
74  * @return NSAPI_ERROR_OK if no credentials provided or authentication was successful
75  * NSAPI_ERROR_AUTH_FAILURE if authentication failed
76  * NSAPI_ERROR_DEVICE_ERROR if communication with the modemm failed
77  */
79 
80  /** Activates PDP context or in PPP mode opens data channel.
81  * Can be overridden by the modem target if 3GPP default implementation if not an option
82  */
83  virtual void do_connect();
84 
85  /** Get the operation specific timeout. Used in synchronous mode when setting the maximum
86  * waiting time. Modem specific implementation can override this to provide different timeouts.
87  *
88  * @param op current operation
89  * @return timeout in milliseconds
90  */
91  virtual uint32_t get_timeout_for_operation(ContextOperation op) const;
92 
93  /** Helper method to call callback function if it is provided
94  *
95  * @param status connection status which is parameter in callback function
96  */
97  void call_network_cb(nsapi_connection_status_t status);
98 
99  virtual nsapi_error_t activate_non_ip_context();
100  virtual nsapi_error_t setup_control_plane_opt();
101  virtual void deactivate_non_ip_context();
102  virtual void deactivate_ip_context();
103  virtual void set_disconnect();
104  virtual void deactivate_context();
105 private:
106 #if NSAPI_PPP_AVAILABLE
107  nsapi_error_t open_data_channel();
108  void ppp_status_cb(nsapi_event_t ev, intptr_t ptr);
109  void ppp_disconnected();
110 #endif // #if NSAPI_PPP_AVAILABLE
111  nsapi_error_t do_activate_context();
112  virtual void activate_context();
113  nsapi_error_t find_and_activate_context();
114  nsapi_error_t activate_ip_context();
115  void check_and_deactivate_context();
116  bool set_new_context(int cid);
117  bool get_context();
118  nsapi_error_t delete_current_context();
119  pdp_type_t string_to_pdp_type(const char *pdp_type);
120  nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op);
121  AT_CellularBase::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type);
122  void ciot_opt_cb(mbed::CellularNetwork::CIoT_Supported_Opt ciot_opt);
123 
124 private:
125  bool _is_connected;
126  bool _is_blocking;
127  ContextOperation _current_op;
128  char _found_apn[MAX_APN_LENGTH];
129  CellularDevice *_device;
130  CellularNetwork *_nw;
131  FileHandle *_fh;
132  rtos::Semaphore _semaphore;
133  rtos::Semaphore _cp_opt_semaphore;
134 
135 protected:
136  // flag indicating if CP was requested to be setup
137  bool _cp_req;
138  // flag indicating if Non-IP context was requested to be setup
139  bool _nonip_req;
140 
141  // tells if CCIOTOPTI received green from network for CP optimization use
142  bool _cp_in_use;
143 };
144 
145 } // namespace mbed
146 
147 #endif // AT_CELLULARCONTEXT_H_
Implements support for data transfer using Control Plane CIoT EPS optimization specified in 3GPP 23...
virtual const char * get_gateway()
Get the local gateways.
virtual void set_sim_pin(const char *sim_pin)
Set the PIN code for SIM card.
virtual const char * get_netmask()
Get the local network mask.
NetworkStack class.
Definition: NetworkStack.h:40
The Semaphore class is used to manage and protect access to a set of shared resources.
Definition: Semaphore.h:45
Class CellularList.
Definition: CellularList.h:30
virtual ControlPlane_netif * get_cp_netif()
Returns the control plane AT command interface.
virtual nsapi_error_t register_to_network()
Start the interface.
CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity...
Class CellularDevice.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
Class FileHandle.
Definition: FileHandle.h:46
void call_network_cb(nsapi_connection_status_t status)
Helper method to call callback function if it is provided.
virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports, CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate)
Get APN rate control.
Class providing buffered UART communication functionality using separate circular buffer for send and...
Definition: UARTSerial.h:50
virtual void do_connect()
Activates PDP context or in PPP mode opens data channel.
virtual nsapi_error_t attach_to_network()
Start the interface.
virtual nsapi_error_t disconnect()
Stop the interface.
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr)
The CellularDevice calls the status callback function on status changes on the network or CellularDev...
virtual void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)
Register callback for status reporting.
virtual void set_plmn(const char *plmn)
Set the plmn.
virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer)
Get backoff timer value.
Cellular PDP context class.
An abstract interface for connecting to a network and getting information from it.
virtual nsapi_error_t set_sim_ready()
Start the interface.
virtual const char * get_ip_address()
Get the local IP address.
virtual nsapi_error_t connect()
Attempt to connect to a cellular network.
Class AT_CellularBase.
virtual void set_file_handle(FileHandle *fh)
Set the file handle used to communicate with the modem.
virtual uint32_t get_timeout_for_operation(ContextOperation op) const
Get the operation specific timeout.
virtual nsapi_error_t set_blocking(bool blocking)
Set asynchronous operation of connect() and disconnect() calls.
virtual nsapi_error_t do_user_authentication()
Does the authentication for the PDP Context if user name and password are provided.
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list)
Get the relevant information for an active nonsecondary PDP context.
virtual void enable_hup(bool enable)
Enable or disable hang-up detection.
virtual nsapi_error_t set_device_ready()
Start the interface.
virtual bool is_connected()
Check if the connection is currently established.
Callback class based on template specialization.
Definition: Callback.h:39
Definition: AnalogIn.h:28
virtual void set_credentials(const char *apn, const char *uname=0, const char *pwd=0)
Set the cellular network credentials.
Class for sending AT commands and parsing AT responses.
Definition: ATHandler.h:62
virtual nsapi_connection_status_t get_connection_status() const
Get the connection status.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.