Mistake on this page?
Report an issue in GitHub or email us
PPPInterface.h
1 /*
2  * Copyright (c) 2019 ARM Limited
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 
18 #ifndef PPP_INTERFACE_H
19 #define PPP_INTERFACE_H
20 
21 #include "nsapi.h"
22 #include "OnboardNetworkStack.h"
23 #include "NetworkInterface.h"
24 #include "PPP.h"
25 
26 
27 /** PPPInterface class
28  * Implementation of the NetworkInterface for an PPP-service
29  *
30  * This class provides the necessary glue logic to create a NetworkInterface
31  * based on an PPP and an OnboardNetworkStack.
32  *
33  */
34 class PPPInterface : public virtual NetworkInterface {
35 public:
36  /** Create an PPP-based network interface.
37  *
38  * The default arguments obtain the default PPP, which will be target-
39  * dependent (and the target may have some JSON option to choose which
40  * is the default, if there are multiple). The default stack is configured
41  * by JSON option nsapi.default-stack.
42  *
43  * Due to inability to return errors from the constructor, no real
44  * work is done until the first call to connect().
45  *
46  * @param ppp Reference to PPP to use
47  * @param stack Reference to onboard-network stack to use
48  */
51  virtual ~PPPInterface();
52 
53  /** Set a static IP address
54  *
55  * Configures this network interface to use a static IP address.
56  * Implicitly disables DHCP, which can be enabled in set_dhcp.
57  * Requires that the network is disconnected.
58  *
59  * @param ip_address Null-terminated representation of the local IP address
60  * @param netmask Null-terminated representation of the local network mask
61  * @param gateway Null-terminated representation of the local gateway
62  * @return 0 on success, negative error code on failure
63  */
64  virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
65 
66  /** Start the interface
67  * @return 0 on success, negative on failure
68  */
69  virtual nsapi_error_t connect();
70 
71  /** Stop the interface
72  * @return 0 on success, negative on failure
73  */
74  virtual nsapi_error_t disconnect();
75 
76  /** Get the local IP address
77  *
78  * @return Null-terminated representation of the local IP address
79  * or null if no IP address has been received
80  */
81  virtual const char *get_ip_address();
82 
83  /** @copydoc NetworkInterface::get_ip_address */
84  virtual nsapi_error_t get_ip_address(SocketAddress *address);
85 
86  /** @copydoc NetworkInterface::get_netmask */
87  virtual nsapi_error_t get_netmask(SocketAddress *address);
88 
89  /** @copydoc NetworkInterface::get_gateway */
90  virtual nsapi_error_t get_gateway(SocketAddress *address);
91 
92  /** Get the local network mask
93  *
94  * @return Null-terminated representation of the local network mask
95  * or null if no network mask has been received
96  */
97  virtual const char *get_netmask();
98 
99  /** Get the local gateways
100  *
101  * @return Null-terminated representation of the local gateway
102  * or null if no network mask has been received
103  */
104  virtual const char *get_gateway();
105 
106  /** Get the network interface name
107  *
108  * @return Null-terminated representation of the network interface name
109  * or null if interface not exists
110  */
111  virtual char *get_interface_name(char *interface_name);
112 
113  /** Set the network interface as default one
114  */
115  virtual void set_as_default();
116 
117  /** Register callback for status reporting
118  *
119  * @param status_cb The callback for status changes
120  */
121  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
122 
123  /** Get the connection status
124  *
125  * @return The connection status according to nsapi_connection_status_t
126  */
127  virtual nsapi_connection_status_t get_connection_status() const;
128 
129  /** Set blocking status of connect() which by default should be blocking
130  *
131  * @param blocking true if connect is blocking
132  * @return 0 on success, negative error code on failure
133  */
134  virtual nsapi_error_t set_blocking(bool blocking);
135 
136  /** Sets file stream used to communicate with modem
137  *
138  * @param stream Pointer to file handle
139  */
140  virtual void set_stream(mbed::FileHandle *stream);
141 
142  /** Sets IP protocol versions of IP stack
143  *
144  * @param ip_stack IP protocol version
145  */
146  virtual void set_ip_stack(nsapi_ip_stack_t ip_stack);
147 
148  /** Sets user name and password for PPP protocol
149  *
150  * @param uname User name
151  * @param password Password
152  */
153  virtual void set_credentials(const char *uname, const char *password);
154 
155  /** Provide access to the PPP
156  *
157  * This should be used with care - normally the network stack would
158  * control the PPP, so manipulating the PPP while the stack
159  * is also using it (ie after connect) will likely cause problems.
160  *
161  * @return Reference to the PPP in use
162  */
163  PPP &getppp() const
164  {
165  return _ppp;
166  }
167 
168  virtual PPPInterface *pppInterface()
169  {
170  return this;
171  }
172 
173 protected:
174  /** Provide access to the underlying stack
175  *
176  * @return The underlying network stack
177  */
178  virtual NetworkStack *get_stack();
179 
180  PPP &_ppp;
181  OnboardNetworkStack &_stack;
182  OnboardNetworkStack::Interface *_interface;
183  bool _blocking;
184  char _ip_address[NSAPI_IPv6_SIZE];
185  char _netmask[NSAPI_IPv4_SIZE];
186  char _gateway[NSAPI_IPv4_SIZE];
187  mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
188 
189  mbed::FileHandle *_stream;
190  nsapi_ip_stack_t _ip_stack;
191  const char *_uname;
192  const char *_password;
193 
194 };
195 
196 #endif
virtual const char * get_netmask()
Get the local network mask.
PPPInterface class Implementation of the NetworkInterface for an PPP-service.
Definition: PPPInterface.h:34
NetworkStack class.
Definition: NetworkStack.h:40
Network Interface base class.
Representation of a stack&#39;s view of an interface.
PPP & getppp() const
Provide access to the PPP.
Definition: PPPInterface.h:163
virtual nsapi_error_t connect()
Start the interface.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
Class FileHandle.
Definition: FileHandle.h:46
virtual void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)
Register callback for status reporting.
virtual void set_stream(mbed::FileHandle *stream)
Sets file stream used to communicate with modem.
virtual nsapi_error_t disconnect()
Stop the interface.
virtual void set_credentials(const char *uname, const char *password)
Sets user name and password for PPP protocol.
virtual const char * get_ip_address()
Get the local IP address.
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway)
Set a static IP address.
mbed OS API for onboard IP stack abstraction
Definition: PPP.h:26
virtual void set_as_default()
Set the network interface as default one.
#define NSAPI_IPv4_SIZE
Size of IPv4 representation.
Definition: nsapi_types.h:160
SocketAddress class.
Definition: SocketAddress.h:35
Common interface that is shared between network devices.
virtual nsapi_connection_status_t get_connection_status() const
Get the connection status.
virtual const char * get_gateway()
Get the local gateways.
virtual char * get_interface_name(char *interface_name)
Get the network interface name.
static PPP & get_default_instance()
Return the default on-board PPP.
#define NSAPI_IPv6_SIZE
Size of IPv6 representation.
Definition: nsapi_types.h:168
PPPInterface(PPP &ppp=PPP::get_default_instance(), OnboardNetworkStack &stack=OnboardNetworkStack::get_default_instance())
Create an PPP-based network interface.
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
Callback class based on template specialization.
Definition: Callback.h:39
virtual NetworkStack * get_stack()
Provide access to the underlying stack.
virtual nsapi_error_t set_blocking(bool blocking)
Set blocking status of connect() which by default should be blocking.
virtual void set_ip_stack(nsapi_ip_stack_t ip_stack)
Sets IP protocol versions of IP stack.
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.