Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PPPInterface.h Source File

PPPInterface.h

00001 /*
00002  * Copyright (c) 2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef PPP_INTERFACE_H
00019 #define PPP_INTERFACE_H
00020 
00021 #include "nsapi.h"
00022 #include "OnboardNetworkStack.h"
00023 #include "NetworkInterface.h"
00024 #include "PPP.h"
00025 
00026 
00027 /** PPPInterface class
00028  *  Implementation of the NetworkInterface for an PPP-service
00029  *
00030  * This class provides the necessary glue logic to create a NetworkInterface
00031  * based on an PPP and an OnboardNetworkStack.
00032  *
00033  */
00034 class PPPInterface : public virtual NetworkInterface {
00035 public:
00036     /** Create an PPP-based network interface.
00037      *
00038      * The default arguments obtain the default PPP, which will be target-
00039      * dependent (and the target may have some JSON option to choose which
00040      * is the default, if there are multiple). The default stack is configured
00041      * by JSON option nsapi.default-stack.
00042      *
00043      * Due to inability to return errors from the constructor, no real
00044      * work is done until the first call to connect().
00045      *
00046      * @param ppp  Reference to PPP to use
00047      * @param stack Reference to onboard-network stack to use
00048      */
00049     PPPInterface(PPP &ppp = PPP::get_default_instance(),
00050                  OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
00051     virtual ~PPPInterface();
00052 
00053     /** @copydoc NetworkInterface::set_network */
00054     virtual nsapi_error_t set_network (const char *ip_address, const char *netmask, const char *gateway);
00055 
00056     /** @copydoc NetworkInterface::connect */
00057     virtual nsapi_error_t connect ();
00058 
00059     /** @copydoc NetworkInterface::disconnect */
00060     virtual nsapi_error_t disconnect ();
00061 
00062     /** @copydoc NetworkInterface::get_ip_address */
00063     virtual const char *get_ip_address ();
00064 
00065     /** @copydoc NetworkInterface::get_ip_address */
00066     virtual nsapi_error_t get_ip_address (SocketAddress *address);
00067 
00068     /** @copydoc NetworkInterface::get_netmask */
00069     virtual nsapi_error_t get_netmask (SocketAddress *address);
00070 
00071     /** @copydoc NetworkInterface::get_gateway */
00072     virtual nsapi_error_t get_gateway (SocketAddress *address);
00073 
00074     /** @copydoc NetworkInterface::get_netmask */
00075     virtual const char *get_netmask ();
00076 
00077     /** @copydoc NetworkInterface::get_gateway */
00078     virtual const char *get_gateway ();
00079 
00080     /** @copydoc NetworkInterface::get_interface_name */
00081     virtual char *get_interface_name (char *interface_name);
00082 
00083     /** @copydoc NetworkInterface::set_as_default */
00084     virtual void set_as_default ();
00085 
00086     /** @copydoc NetworkInterface::attach */
00087     virtual void attach (mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
00088 
00089     /** @copydoc NetworkInterface::get_connection_status */
00090     virtual nsapi_connection_status_t get_connection_status () const;
00091 
00092     /** @copydoc NetworkInterface::set_blocking */
00093     virtual nsapi_error_t set_blocking (bool blocking);
00094 
00095     /** Sets file stream used to communicate with modem
00096      *
00097      * @param stream Pointer to file handle
00098      */
00099     virtual void set_stream(mbed::FileHandle *stream);
00100 
00101     /** Sets IP protocol versions of IP stack
00102      *
00103      * @param ip_stack IP protocol version
00104      */
00105     virtual void set_ip_stack(nsapi_ip_stack_t ip_stack);
00106 
00107     /** Sets user name and password for PPP protocol
00108      *
00109      * @param uname    User name
00110      * @param password Password
00111      */
00112     virtual void set_credentials(const char *uname, const char *password);
00113 
00114     /** Provide access to the PPP
00115      *
00116      * This should be used with care - normally the network stack would
00117      * control the PPP, so manipulating the PPP while the stack
00118      * is also using it (ie after connect) will likely cause problems.
00119      *
00120      * @return          Reference to the PPP in use
00121      */
00122     PPP &getppp() const
00123     {
00124         return _ppp;
00125     }
00126 
00127     virtual PPPInterface *pppInterface()
00128     {
00129         return this;
00130     }
00131 
00132 protected:
00133     /** Provide access to the underlying stack
00134      *
00135      *  @return The underlying network stack
00136      */
00137     virtual NetworkStack *get_stack();
00138 
00139     PPP &_ppp;
00140     OnboardNetworkStack &_stack;
00141     OnboardNetworkStack::Interface *_interface;
00142     bool _blocking;
00143     char _ip_address[NSAPI_IPv6_SIZE];
00144     char _netmask[NSAPI_IPv4_SIZE];
00145     char _gateway[NSAPI_IPv4_SIZE];
00146     mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
00147 
00148     mbed::FileHandle *_stream;
00149     nsapi_ip_stack_t _ip_stack;
00150     const char *_uname;
00151     const char *_password;
00152 
00153 };
00154 
00155 #endif