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  ~PPPInterface() override;
52 
53  /** @copydoc NetworkInterface::set_network */
54  nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override;
55 
56  /** @copydoc NetworkInterface::connect */
57  nsapi_error_t connect() override;
58 
59  /** @copydoc NetworkInterface::disconnect */
60  nsapi_error_t disconnect() override;
61 
62  /** @copydoc NetworkInterface::get_ip_address */
63  nsapi_error_t get_ip_address(SocketAddress *address) override;
64 
65  /** @copydoc NetworkInterface::get_netmask */
66  nsapi_error_t get_netmask(SocketAddress *address) override;
67 
68  /** @copydoc NetworkInterface::get_gateway */
69  nsapi_error_t get_gateway(SocketAddress *address) override;
70 
71  /** @copydoc NetworkInterface::get_interface_name */
72  char *get_interface_name(char *interface_name) override;
73 
74  /** @copydoc NetworkInterface::set_as_default */
75  void set_as_default() override;
76 
77  /** @copydoc NetworkInterface::attach */
78  void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
79 
80  /** @copydoc NetworkInterface::get_connection_status */
81  nsapi_connection_status_t get_connection_status() const override;
82 
83  /** @copydoc NetworkInterface::set_blocking */
84  nsapi_error_t set_blocking(bool blocking) override;
85 
86  /** Sets file stream used to communicate with modem
87  *
88  * @param stream Pointer to file handle
89  */
90  void set_stream(mbed::FileHandle *stream);
91 
92  /** Sets IP protocol versions of IP stack
93  *
94  * @param ip_stack IP protocol version
95  */
96  void set_ip_stack(nsapi_ip_stack_t ip_stack);
97 
98  /** Sets user name and password for PPP protocol
99  *
100  * @param uname User name
101  * @param password Password
102  */
103  void set_credentials(const char *uname, const char *password);
104 
105  /** Provide access to the PPP
106  *
107  * This should be used with care - normally the network stack would
108  * control the PPP, so manipulating the PPP while the stack
109  * is also using it (ie after connect) will likely cause problems.
110  *
111  * @return Reference to the PPP in use
112  */
113  PPP &getppp() const
114  {
115  return _ppp;
116  }
117 
118 #if 0
119  /* NetworkInterface does not currently have pppInterface, so this
120  * "dynamic cast" is non-functional.
121  */
122  PPPInterface *pppInterface() final
123  {
124  return this;
125  }
126 #endif
127 
128 protected:
129  /** Provide access to the underlying stack
130  *
131  * @return The underlying network stack
132  */
133  NetworkStack *get_stack() final;
134 
135  PPP &_ppp;
136  OnboardNetworkStack &_stack;
137  OnboardNetworkStack::Interface *_interface = nullptr;
138  bool _blocking = true;
139  char _ip_address[NSAPI_IPv6_SIZE] {};
140  char _netmask[NSAPI_IPv4_SIZE] {};
141  char _gateway[NSAPI_IPv4_SIZE] {};
142  mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
143 
144  mbed::FileHandle *_stream = nullptr;
145  nsapi_ip_stack_t _ip_stack = DEFAULT_STACK;
146  const char *_uname = nullptr;
147  const char *_password = nullptr;
148 
149 };
150 
151 #endif
void set_credentials(const char *uname, const char *password)
Sets user name and password for PPP protocol.
PPPInterface class Implementation of the NetworkInterface for an PPP-service.
Definition: PPPInterface.h:34
nsapi_error_t disconnect() override
Disconnect from the network.
NetworkStack class.
Definition: NetworkStack.h:42
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:113
NetworkStack * get_stack() final
Provide access to the underlying stack.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:140
Class FileHandle.
Definition: FileHandle.h:46
char * get_interface_name(char *interface_name) override
Get the network interface name.
mbed OS API for onboard IP stack abstraction
nsapi_error_t connect() override
Connect to a network.
void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) override
Register callback for status reporting.
void set_stream(mbed::FileHandle *stream)
Sets file stream used to communicate with modem.
Definition: PPP.h:26
nsapi_error_t set_blocking(bool blocking) override
Set asynchronous operation of connect() and disconnect() calls.
void set_ip_stack(nsapi_ip_stack_t ip_stack)
Sets IP protocol versions of IP stack.
#define NSAPI_IPv4_SIZE
Size of IPv4 representation.
Definition: nsapi_types.h:207
SocketAddress class.
Definition: SocketAddress.h:37
Common interface that is shared between network devices.
nsapi_error_t get_gateway(SocketAddress *address) override
Get the local gateway.
static PPP & get_default_instance()
Return the default on-board PPP.
nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override
Configure this network interface to use a static IP address.
nsapi_error_t get_ip_address(SocketAddress *address) override
Get the local IP address.
#define NSAPI_IPv6_SIZE
Size of IPv6 representation.
Definition: nsapi_types.h:215
void set_as_default() override
Set network interface as default one.
PPPInterface(PPP &ppp=PPP::get_default_instance(), OnboardNetworkStack &stack=OnboardNetworkStack::get_default_instance())
Create an PPP-based network interface.
nsapi_error_t get_netmask(SocketAddress *address) override
Get the local network mask.
nsapi_connection_status_t get_connection_status() const override
Get the connection status.
static OnboardNetworkStack & get_default_instance()
Return the default on-board network stack.
Callback class based on template specialization.
Definition: Callback.h:53
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.