Mistake on this page?
Report an issue in GitHub or email us
CellularBase.h
1 /* Copyright (c) 2017 ARM Limited
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CELLULAR_BASE_H
17 #define CELLULAR_BASE_H
18 
19 #include "netsocket/NetworkInterface.h"
20 
21 /** CellularBase class
22  *
23  * Common interface that is shared between Cellular interfaces
24  */
26 
27 public:
28 
29  /** Get the default Cellular interface.
30  *
31  * This is provided as a weak method so applications can override.
32  * Default behaviour is to get the target's default interface, if
33  * any.
34  *
35  * @return pointer to interface, if any
36  */
37 
39 
40  /** Set the Cellular network credentials
41  *
42  * Please check documentation of connect() for default behaviour of APN settings.
43  *
44  * @param apn Access point name
45  * @param uname optionally, Username
46  * @param pwd optionally, password
47  */
48  virtual void set_credentials(const char *apn, const char *uname = 0,
49  const char *pwd = 0) = 0;
50 
51  /** Set the pin code for SIM card
52  *
53  * @param sim_pin PIN for the SIM card
54  */
55  virtual void set_sim_pin(const char *sim_pin) = 0;
56 
57  /** Start the interface
58  *
59  * Attempts to connect to a Cellular network.
60  *
61  * @param sim_pin PIN for the SIM card
62  * @param apn optionally, access point name
63  * @param uname optionally, Username
64  * @param pwd optionally, password
65  * @return NSAPI_ERROR_OK on success, or negative error code on failure
66  */
67  virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0,
68  const char *uname = 0,
69  const char *pwd = 0) = 0;
70 
71  /** Start the interface
72  *
73  * Attempts to connect to a Cellular network.
74  * If the SIM requires a PIN, and it is not set/invalid, NSAPI_ERROR_AUTH_ERROR is returned.
75  *
76  * @return NSAPI_ERROR_OK on success, or negative error code on failure
77  */
78  virtual nsapi_error_t connect() = 0;
79 
80  /** Stop the interface
81  *
82  * @return 0 on success, or error code on failure
83  */
84  virtual nsapi_error_t disconnect() = 0;
85 
86  /** Check if the connection is currently established or not
87  *
88  * @return true/false If the cellular module have successfully acquired a carrier and is
89  * connected to an external packet data network using PPP, isConnected()
90  * API returns true and false otherwise.
91  */
92  virtual bool is_connected() = 0;
93 
94  /** Get the local IP address
95  *
96  * @return Null-terminated representation of the local IP address
97  * or null if no IP address has been received
98  */
99  virtual const char *get_ip_address() = 0;
100 
101  /** Get the local network mask
102  *
103  * @return Null-terminated representation of the local network mask
104  * or null if no network mask has been received
105  */
106  virtual const char *get_netmask() = 0;
107 
108  /** Get the local gateways
109  *
110  * @return Null-terminated representation of the local gateway
111  * or null if no network mask has been received
112  */
113  virtual const char *get_gateway() = 0;
114 
116  return this;
117  }
118 
119 protected:
120  /** Get the target's default Cellular interface.
121  *
122  * This is provided as a weak method so targets can override. The
123  * default implementation configures and returns the OnBoardModemInterface
124  * if available.
125  *
126  * @return pointer to interface, if any
127  */
129 };
130 
131 #endif //CELLULAR_BASE_H
132 
133 /** @}*/
virtual nsapi_error_t disconnect()=0
virtual const char * get_ip_address()=0
static CellularBase * get_target_default_instance()
Definition: OnboardCellularInterface.cpp:74
virtual bool is_connected()=0
signed int nsapi_error_t
Definition: nsapi_types.h:94
virtual void set_sim_pin(const char *sim_pin)=0
virtual const char * get_gateway()=0
virtual const char * get_netmask()=0
virtual CellularBase * cellularBase()
Definition: CellularBase.h:115
Definition: NetworkInterface.h:39
static CellularBase * get_default_instance()
Definition: NetworkInterfaceDefaults.cpp:43
Definition: CellularBase.h:25
virtual nsapi_error_t connect()=0
virtual void set_credentials(const char *apn, const char *uname=0, const char *pwd=0)=0
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.