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  /** Get the local network mask
84  *
85  * @return Null-terminated representation of the local network mask
86  * or null if no network mask has been received
87  */
88  virtual const char *get_netmask();
89 
90  /** Get the local gateways
91  *
92  * @return Null-terminated representation of the local gateway
93  * or null if no network mask has been received
94  */
95  virtual const char *get_gateway();
96 
97  /** Get the network interface name
98  *
99  * @return Null-terminated representation of the network interface name
100  * or null if interface not exists
101  */
102  virtual char *get_interface_name(char *interface_name);
103 
104  /** Set the network interface as default one
105  */
106  virtual void set_as_default();
107 
108  /** Register callback for status reporting
109  *
110  * @param status_cb The callback for status changes
111  */
112  virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
113 
114  /** Get the connection status
115  *
116  * @return The connection status according to nsapi_connection_status_t
117  */
118  virtual nsapi_connection_status_t get_connection_status() const;
119 
120  /** Set blocking status of connect() which by default should be blocking
121  *
122  * @param blocking true if connect is blocking
123  * @return 0 on success, negative error code on failure
124  */
125  virtual nsapi_error_t set_blocking(bool blocking);
126 
127  /** Sets file stream used to communicate with modem
128  *
129  * @param stream Pointer to file handle
130  */
131  virtual void set_stream(mbed::FileHandle *stream);
132 
133  /** Sets IP protocol versions of IP stack
134  *
135  * @param ip_stack IP protocol version
136  */
137  virtual void set_ip_stack(nsapi_ip_stack_t ip_stack);
138 
139  /** Sets user name and password for PPP protocol
140  *
141  * @param uname User name
142  * @param password Password
143  */
144  virtual void set_credentials(const char *uname, const char *password);
145 
146  /** Provide access to the PPP
147  *
148  * This should be used with care - normally the network stack would
149  * control the PPP, so manipulating the PPP while the stack
150  * is also using it (ie after connect) will likely cause problems.
151  *
152  * @return Reference to the PPP in use
153  */
154  PPP &getppp() const
155  {
156  return _ppp;
157  }
158 
159  virtual PPPInterface *pppInterface()
160  {
161  return this;
162  }
163 
164 protected:
165  /** Provide access to the underlying stack
166  *
167  * @return The underlying network stack
168  */
169  virtual NetworkStack *get_stack();
170 
171  PPP &_ppp;
172  OnboardNetworkStack &_stack;
173  OnboardNetworkStack::Interface *_interface;
174  bool _blocking;
175  char _ip_address[NSAPI_IPv6_SIZE];
176  char _netmask[NSAPI_IPv4_SIZE];
177  char _gateway[NSAPI_IPv4_SIZE];
178  mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
179 
180  mbed::FileHandle *_stream;
181  nsapi_ip_stack_t _ip_stack;
182  const char *_uname;
183  const char *_password;
184 
185 };
186 
187 #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:154
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
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.